4

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

2 Answers 2

1

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});
Sign up to request clarification or add additional context in comments.

8 Comments

Hmm, i have AreaRegistration.RegisterAllAreas() on top of Application_Start() function in global.asax
Yes, i have folder EmployeeReportArea under Areas folder. Fixed in first comment.
My mistake, the fact that it was searching for the view meant that it found the route. Try using haacked.com/archive/2008/03/13/url-routing-debugger.aspx and see if this helps.
I have looked at my own code, and I do not specify "area" in my route registration... try removing that property.
Do not add directly to Context.Routes. Use overriden MapRoute function, that handles Area for you.
|
0

Your folder structure for your area should look like so:

  • Areas
    • EmployeeReport
      • Controllers
      • Views

1 Comment

Yes, sorry it was mistake while I posting question. Fixed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.