由于某些特定原因,我需要 .NET MVC 4 不要自动从 URL 中删除“索引”。基本上我需要转换
http://example.com/到 http://example.com/Index
或
http://example.com/foo 到 http://example.com/foo/Index
问题是 @URL.Action("Index", "Foo") 只输出/Foo,我需要它输出 Foo/Index。
任何帮助将不胜感激!
最佳答案
您应该能够从路由映射中删除默认操作。
所以代替这个:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
只需取出action = "Index"
:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", id = UrlParameter.Optional }
);
关于asp.net-mvc - MVC 4 : add "Index" to url path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15760585/