映射路由、查询和 mvc

发布于 2024-07-10 03:06:56 字数 629 浏览 10 评论 0原文

我有两条路线:

routes.MapRoute(
            "FetchVenue",                                     
            "venue/fetchlike/{q}",                                     
            new { controller = "venue", action = "fetchlike" }      
        );

        routes.MapRoute(
            "venue",                                         
            "venue/{venueId}",                                 
            new { controller = "Venue", action = "Index" }   
);

url /venue/fetchlike/test 被传递到正确的控制器 然而,url /venue/fetchlike/?q=test 被传递给索引操作。

我希望能够将数据作为查询字符串传递。

我究竟做错了什么?

I have two routes:

routes.MapRoute(
            "FetchVenue",                                     
            "venue/fetchlike/{q}",                                     
            new { controller = "venue", action = "fetchlike" }      
        );

        routes.MapRoute(
            "venue",                                         
            "venue/{venueId}",                                 
            new { controller = "Venue", action = "Index" }   
);

The url /venue/fetchlike/test is passed to the correct controller
The url /venue/fetchlike/?q=test is however passed to the index action.

I want to be able to pass data as a querystring.

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

趴在窗边数星星i 2024-07-17 03:06:56

实际上,问题是路线:

 routes.MapRoute( "FetchVenue", "venue/fetchlike/{q}",  new { controller = "venue", action = "fetchlike" });

实际上应该是:

 routes.MapRoute( "FetchVenue", "venue/fetchlike",  new { controller = "venue", action = "fetchlike" });

这意味着网址应该是:

/venue/fetchlike?q=test,

如strelokstrelok上面建议的那样。

因此,在查询参数的情况下,您不要在路由中定义它们!

Actually the issue was that the route:

 routes.MapRoute( "FetchVenue", "venue/fetchlike/{q}",  new { controller = "venue", action = "fetchlike" });

should actually have been:

 routes.MapRoute( "FetchVenue", "venue/fetchlike",  new { controller = "venue", action = "fetchlike" });

Meaning that the url would have been:

/venue/fetchlike?q=test

as suggested above by strelokstrelok.

So, in the case of querysting parameters, you DONT define them in the route!

疯狂的代价 2024-07-17 03:06:56

我突然想到,你的网址不应该是 /venue/fetchlike?q=test,而不是 /venue/fetchlike/?q=test

Just off the top of my head, shouldn't your URL look like /venue/fetchlike?q=test, instead of /venue/fetchlike/?q=test

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文