ASP中的区域路由问题.净MVC
本文关键字:问题 MVC 路由 区域 ASP | 更新日期: 2023-09-27 17:53:49
似乎区域路由对我来说是一个问题。这是我的问题,我有一个名为Administration的应用程序,我有一个名为DepartmentController的控制器。现在我需要创建一个路由,生成一个类似http://www.example.com/Administration/Setup/Department的链接。
这是我所做的。
在Route。我添加了一个自定义路由,如下所示:
routes.MapRoute(
name: "DeptSetup",
url: "Setup/Department/{action}/{id}",
defaults: new { controller = "Department", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "Administration.Controllers" }
);
我得到了资源找不到。
我尝试了adminationareregistration如下:
context.MapRoute(
name: "DeptSetup",
url: "Setup/Department/{action}/{id}",
defaults: new { controller = "Department", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "Administration.Controllers" }
);
都不工作。请给我指个正确的方向。
谢谢
你缺少路由URL模板中的区域部分。使用AdmininstrationAreaRegistration
是一种正确的方式,因为区域应该负责注册自己的路由,但路由本身应该看起来像:
url: "Administration/Setup/Department/{action}/{id}"
您应该使用区域注册 (AdmininstrationAreaRegistration
)类,并应添加管理员(区域名称)到您的url
模板:
context.MapRoute(
name: "DeptSetup",
url: "Administrator/Setup/{controller}/{action}/{id}",
defaults: new { controller = "Department", action = "Index", id = UrlParameter.Optional }
);