I can't work out how to direct asp.net mvc to the desired controller for a request to my site's root.
I've tried lots of different entries in RegisterRoutes including:
routes.MapRoute(
"MyHome",
"",
new { controller = "MyController", action = "Index", id = UrlParameter.Optional }
);
The error I get is:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Home/Index.aspx ~/Views/Home/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx ~/Views/Home/Index.cshtml ~/Views/Home/Index.vbhtml ~/Views/Shared/Index.cshtml ~/Views/Shared/Index.vbhtml
How can I get web site root requests going to the desired controller?
Update: Still couldn't fix the issue so created a new MVC project which worked out of the box. I did rename the original project a couple of times so perhaps that screwed things up somewhere.
Based on the error message...
It is going to the controller called HomeController. So, I'm guessing you have another route (maybe the default?) that directs it to the HomeController?
The error message is about the view not the controller. That is a different issue from routing.
The simplest way to achieve what you are asking would be to edit the default route that was created when you created the MVC3 project.
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "MyController", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);