ASP.NET MVC 3 Routing Multiple parameters without query string

孤人 提交于 2020-01-02 21:00:36

问题


I have the below route setup but it is not coming out the way I am expecting. Yes I am still new to MVC.

The way it is coming out is like this.

http://localhost:29998/Home/States?make=Chrysler

the way I want it to come out is like this

http://localhost:29998/Home/Chrysler/States

Then of course once you click on your state it would look like this.

http://localhost:29998/Home/Chrysler/Florida

I would realy love to be able to remove "home from that altogether and just leave it as

http://localhost:29998/Chrysler/States

routes.MapRoute(
                "States", // Route name
                "{controller}/{action}/{make}", // URL with parameters
                new { controller = "Home", action = "States", Make = "" } // Parameter defaults
            );

回答1:


Here is your solution:

localhost:29998/Chrysler/States

routes.MapRoute(
                "States", // Route name
                "{make}/{states}/", // URL with parameters
                new { controller = "Home", action = "GetStateData", make="", states="" } 
            );

You should place it below the default routing method so it does not take your controller values.



来源:https://stackoverflow.com/questions/10791778/asp-net-mvc-3-routing-multiple-parameters-without-query-string

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