我在为 asp.net mvc3 应用程序创建 ulr 路由时遇到问题。
我的项目具有以下结构:
- 领域
- 员工报告
- Controller
- 报告
- 观看次数
- 报告
- 列表
- ...
- 报告
- Controller
- 员工报告
- Controller
- 登录
- 浏览次数
- 登录
- ...
- 登录
EmployeeReportAreaRegistration.cs:
公共(public)类 EmployeeReportAreaRegistration : AreaRegistration
{
公共(public)覆盖字符串区域名称
{
得到
{
返回“员工报告”;
}
}
公共(public)覆盖无效RegisterArea(AreaRegistrationContext上下文)
{
var 路由 = context.Routes;
paths.MapRoute(null, "vykazy/vykazy-zamestnance", new { Area = "EmployeeReport",controller = "Report", action = "List"});
}
}
全局.asax:
routes.MapRoute(null, "prihlasit", new {controller = "登录", action = "登录"});
paths.MapRoute("默认", "{controller}/{action}/{id}", new {controller = "默认", action = "欢迎", id = UrlParameter.Optional });
When i try load "http://localhost/app_name/vykazy/vykazy-zamestnance
i get this exception :
The view 'List' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Report/List.aspx
~/Views/Report/List.ascx
~/Views/Shared/List.aspx
~/Views/Shared/List.ascx
~/Views/Report/List.cshtml
~/Views/Report/List.vbhtml
~/Views/Shared/List.cshtml
~/Views/Shared/List.vbhtml
那么,我哪里出错了?
谢谢
最佳答案
修改后的答案:
直接添加到 Context.Routes 意味着它会丢失有关区域的任何信息。
要么使用AreaRegistration.MapRoute(它被覆盖以放入区域信息)。
context.MapRoute(...);
或者将该区域放入 DataTokens 参数中(而不是像您在此处所做的那样使用默认参数)
context.Routes.MapRoute("", "url", new {...}, null, new {area = this.AreaName});
关于asp.net mvc 3 领域和 url 路由配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7471751/