ASP.NET MVC 3路由没有查询字符串的多个参数 [英] ASP.NET MVC 3 Routing Multiple parameters without query string
本文介绍了ASP.NET MVC 3路由没有查询字符串的多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有以下路线设置,但未达到我期望的方式.是的,我还是MVC的新手.
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
);
推荐答案
这是您的解决方案:
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.
这篇关于ASP.NET MVC 3路由没有查询字符串的多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文