问题
I cannot set the Default Route for my MVC project. When I run the project, it goes to the address http://localhost:7555/ and it give the "HTTP ERROR 404" but if I enter the url http://localhost:7555/Default , it goes to the Default page. But I want users to go the Default page even if they dont enter http://localhost:7555/Default.
here is my Route in Global.asax
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{Filtre}", // URL with parameters
new { controller = "Default", action = "Index", Filtre = UrlParameter.Optional } // Parameter defaults
);
what am I supposed to do?
回答1:
Generally if you want this functionality you would have a HomeController
that just works out of the box with the route config. You've chosen instead to have DefaultController
instead - so we need to work it a little differently:
routes.MapRoute(
"Default",
"{action}/{Filtre}",
new { controller = "Default", action = "Index", Filtre = UrlParameter.Optional }
);
来源:https://stackoverflow.com/questions/29987078/cannot-set-default-route-for-mvc-project