Default controller for scope?

This is kind of a duplicate Problem with default controller setting in MVC 2 RC scope

But his answer doesn't satisfy me because it doesn't work.

I have the following

/Areas/TestArea/Controllers/HelloController
/Areas/TestArea/Views/Hello/Index

/Controllers/HomeController
/Views/Home/Index

      

With the following routes:

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

routes.MapRoute(
    "Default2", // Route name
    "TestArea/{controller}/{action}/{id}", // URL with parameters
    new { controller = "Hello", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

      

I added a second one to try http: // servername / TestArea work as if it were http: // servername / TestArea / Hello , but was met with no success. The main http: // servername / is working as intended.

So the question is, how do you return the default controller in the scope?

Edit: I downloaded a sample project to show what I mean: http://beginningasp.net/TestAsync.zip

+2


a source to share


1 answer


Try registering default route2 to default route and set scope = yourareaname to defaults



routes.MapRoute(
    "Default2", // Route name
    "TestArea/{controller}/{action}/{id}", // URL with parameters
    new { controller = "Hello", action = "Index",area="TestArea",  id = UrlParameter.Optional } // Parameter defaults
);

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

      

+3


a source







All Articles