I am rather new to the MVC 3 environment, and I need help.
I am trying to setup a MVC environment in a portal type of scenerio. So I setup a base project for MVC 3 in VS 2010. The following is the folder structure:
Common
Controllers
Resources
Views
Project1
Controllers
Views
Project2
Controllers
Views
While entering a route for "Project1/home", I found a conflict in the routing engine that I am not sure how to debug. Here is the routing:
routes.MapRoute("Project1Default",
"Project1/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "Project1.Controllers" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new [] { "Portal.Controllers" }
When I try the portal url "http://portal", the Project1Default route is invoke!!! On the other hand, when I reverse the mapping order I am sent to the correct page "Default".
How can I make the first route not match the empty request. I thought that by adding the prefix 'Project1' to the pattern would take care of that.
eherrera
Member
5 Points
4 Posts
Routing question
Feb 29, 2012 03:35 PM|LINK
Hi All,
I am rather new to the MVC 3 environment, and I need help.
I am trying to setup a MVC environment in a portal type of scenerio. So I setup a base project for MVC 3 in VS 2010. The following is the folder structure:
While entering a route for "Project1/home", I found a conflict in the routing engine that I am not sure how to debug. Here is the routing:
routes.MapRoute("Project1Default",
"Project1/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "Project1.Controllers" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new [] { "Portal.Controllers" }
When I try the portal url "http://portal", the Project1Default route is invoke!!! On the other hand, when I reverse the mapping order I am sent to the correct page "Default".
How can I make the first route not match the empty request. I thought that by adding the prefix 'Project1' to the pattern would take care of that.
Thanks for your help.
E.
eherrera
Member
5 Points
4 Posts
Re: Routing question
Feb 29, 2012 05:10 PM|LINK
I used a library to debug the routes (http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx) and as it turns out, the routing is working correctly.
The issue might be with the controller/view in the Project1 folder.
Thanks,
E.