[英]Subfolder in controller prefixes Url.Action
我有下一个结构:
Controllers
Epic
PmController.cs
HomeController.cs
在我的App_Start \\ RouteConfig.cs中,我添加了: 更新 -添加了完整方法
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Epic",
url: "Epic/{controller}/{action}",
defaults: new { controller = "Pm", action = "Index" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Default", action = "Index", id = UrlParameter.Optional }
);
}
但是以某种方式@ Url.Action始终以“ Epic”为前缀。 我在其他这样的视图/控制器中使用@ Url.Action:
<a href="@Url.Action("Links", "Home")">Links</a></li> // generates /Epic/Home/Links instead of just /Home/Links
在添加此子文件夹和路由之前,LINKs工作正常。
另外,可以在Controller中使用子文件夹或始终使用Areas 。
好像您删除了默认路由,只需将其再次添加到RouteConfig文件中即可:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.