我在为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" });
}
}
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 });
routes.MapRoute(null, "prihlasit", new { controller = "Login", action = "Login" });
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Default", action = "Welcome", id = UrlParameter.Optional });
嗯,我错在哪里?
由于
答案 0 :(得分:1)
修改后的答案:
直接添加到Context.Routes意味着它会丢失有关区域的任何信息。
使用AreaRegistration.MapRoute(覆盖以放入区域信息)。
context.MapRoute(...);
或者将该区域放在DataTokens参数中(而不是像在此处所做的默认参数)
context.Routes.MapRoute("", "url", new {...}, null, new {area = this.AreaName});
答案 1 :(得分:0)
您所在地区的文件夹结构应如下所示: