Asp.net mvc 3 areas and URL routing configuration

I have a problem creating ulr routing for an asp.net mvc3 application.

My project has the following structure:

  • Areas
    • EmployeeReport
      • Controllers
        • To report
      • Views
        • Report
          • List
          • ....
  • Controllers
    • entrance
  • Viwes
    • To come in
      • ...

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" }); } } 

code>

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 }); 

code>

 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 am I mistaken?

thanks

+4
source share
2 answers

revised answer:

Adding to Context.Routes directly means that it is losing information about Regions.

Or use AreaRegistration.MapRoute (which is overridden to enter Area information).

 context.MapRoute(...); 

Or put the area in the DataTokens parameter (and not the default parameter as you did)

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

Your folder structure for your area should look like this:

  • Areas
    • EmployeeReport
      • Controllers
      • Kinds
0
source

All Articles