映射路由、查询和 mvc
我有两条路线:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,问题是路线:
实际上应该是:
这意味着网址应该是:
/venue/fetchlike?q=test,
如strelokstrelok上面建议的那样。
因此,在查询参数的情况下,您不要在路由中定义它们!
Actually the issue was that the route:
should actually have been:
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!
我突然想到,你的网址不应该是
/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