开发者

asp.net mvc 3 areas and url routing configuration

开发者 https://www.devze.com 2023-04-05 16:51 出处:网络
I have problem with create ulr routing for asp.net mvc3 application. My project has this structure : Areas

I have problem with create ulr routing for asp.net mvc3 application.

My project has this structure :

  • Areas
    • EmployeeReport
      • Controllers
        • Report
      • Views
        • Report
          • List
          • ....
  • Controllers
    • Login
  • Viwes
    • Login
      • ...

EmployeeReportAreaRegistration.cs :

public 开发者_Go百科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


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).

context.MapRoute(...);

Or put the area in the DataTokens parameter (not the defaults parameter as you have done here)

context.Routes.MapRoute("", "url", new {...}, null, new {area = this.AreaName});


Your folder structure for your area should look like so:

  • Areas
    • EmployeeReport
      • Controllers
      • Views
0

精彩评论

暂无评论...
验证码 换一张
取 消