MVC3 映射路由,其中 URL 的第一个值是默认控制器和操作的查询字符串
我想制作一条类似这样的路线:
routes.MapRoute(
"Default", // Route name
"{s}", // URL with parameters
new { controller = "Home", action = "Index", s = UrlParameter.Optional }
);
其中 s 是默认控制器和操作的参数。这可能吗?我也会满足于类似的东西:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{s}", // URL with parameters
new { controller = "Home", action = "Index", s = UrlParameter.Optional }
);
routes.MapRoute(
"qMap", // Route name
"sc/{s}", // URL with parameters
new { controller = "Home", action = "Index", s = UrlParameter.Optional }
);
但两者都不起作用..我怀疑是因为第一个元素/参数总是期望是控制器?
I want to make a route something like this:
routes.MapRoute(
"Default", // Route name
"{s}", // URL with parameters
new { controller = "Home", action = "Index", s = UrlParameter.Optional }
);
Where s is a parameter for the default controller and action.. Is this possible? i would also settle for something like:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{s}", // URL with parameters
new { controller = "Home", action = "Index", s = UrlParameter.Optional }
);
routes.MapRoute(
"qMap", // Route name
"sc/{s}", // URL with parameters
new { controller = "Home", action = "Index", s = UrlParameter.Optional }
);
But neither work.. i suspect because the first element/paramater is always expected to be a controller?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只有以下路由定义(确保已从 RegisterRoutes 方法中删除所有其他路由定义):
和以下控制器:
表单
http://foo.com/abc
的请求将被路由到Home
控制器,并且Index
操作将被调用并传递s=abc
。If you have only the following route definition (make sure you have removed all other route definitions from your RegisterRoutes method):
and the following controller:
a request of the form
http://foo.com/abc
would be routed to theHome
controller and theIndex
action will be invoked and passeds=abc
.