cannot set Default route for MVC project

前提是你 提交于 2019-12-13 19:46:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!