我有一个位于区域内的自定义路由:
[RouteArea("MyArea")]
public class MyController: Controller
{
[Route("~/my-action")]
public ActionResult MyAction()
{
return View();
}
}
在添加 Route 和 RouteArea 属性之前,我通过以下路由访问此操作:
~/MyArea/MyController/MyAction
现在我添加了这些属性,我可以通过以下方式访问它:
~/my-action
我曾经有一个ActionLink指向这个操作,它看起来像这样:
@Html.ActionLink("Link To My Action", "MyAction", "My", new { Area = "MyArea" }, new { })
现在这个ActionLink已经不能正常工作了,我该怎么修复它?
ActionLink
永远不会生效 - 你的控制器名字是MyController
,所以需要这样写才行@Html.ActionLink("Link To My Action", "MyAction", "My", new { Area = "MyArea" }, new { })
。 - user3559349RouteConfig.cs
文件中像这样初始化了这个功能:在RegisterRoutes
方法中添加routes.MapMvcAttributeRoutes()
? - Marko Jovanov