asp.net mvc 3 领域和 url 路由配置
我在为 asp.net mvc3 应用程序创建 ulr 路由时遇到问题。
我的项目具有以下结构:
- 区域
- 员工报告
- 控制器
- 报告
- 观看次数
- 报告
- 列表
- ...
- 报告
- 控制器
- 员工报告
- 控制器
- 登录
- 视图
- 登录
- ...
登录
- 登录
EmployeeReportAreaRegistration.cs :
public class EmployeeReportAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "EmployeeReport";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
var routes = context.Routes;
routes.MapRoute(null, "vykazy/vykazy-zamestnance", new { Area = "EmployeeReport", controller = "Report", action = "List" });
}
}
Global.asax:
routes.MapRoute(null, "prihlasit", new { controller = "Login", action = "Login" });
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Default", action = "Welcome", 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
那么,我在哪里出错了?
谢谢
I have problem with create ulr routing for asp.net mvc3 application.
My project has this structure :
- Areas
- EmployeeReport
- Controllers
- Report
- Views
- Report
- List
- ....
- Report
- Controllers
- EmployeeReport
- Controllers
- Login
- Viwes
- Login
- ...
- Login
EmployeeReportAreaRegistration.cs :
public class EmployeeReportAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "EmployeeReport";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
var routes = context.Routes;
routes.MapRoute(null, "vykazy/vykazy-zamestnance", new { Area = "EmployeeReport", controller = "Report", action = "List" });
}
}
Global.asax :
routes.MapRoute(null, "prihlasit", new { controller = "Login", action = "Login" });
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Default", action = "Welcome", 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
Well, where I do mistake ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
修改后的答案:
直接添加到 Context.Routes 意味着它会丢失有关区域的任何信息。
要么使用 AreaRegistration.MapRoute (它被覆盖以放入区域信息)。
或者将该区域放入 DataTokens 参数中(而不是像您在此处所做的那样使用默认参数)
revised answer:
Adding to Context.Routes directly means it loses any information about Areas.
Either use AreaRegistration.MapRoute (which is overriden to put in the Area information).
Or put the area in the DataTokens parameter (not the defaults parameter as you have done here)
您所在区域的文件夹结构应如下所示:
Your folder structure for your area should look like so: