我当前的网址是这样的 => http://localhost:4330/Restaurants/?Location=Manchester&Cuisine=0&NetProfit=0&Turnover=0&MaxPrice=120000&SortPriceBy=Low&Page=0
我希望它能做出这样的东西 => http://localhost:4330/Restaurants/Manchester/?Cuisine=Chinese&MaxPrice=120000
其中没有值 (0) 的参数查询字符串不会包含在查询字符串 URL 中 可能吗?
最佳答案
已更新
字符串将此添加到 Global.asax 路由
routes.MapRoute(
"Name of route", // Route name
"Restaurants/{cityid}/", // URL with parameters
new { controller = "Restaurants", action = "Index" } // Parameter defaults
);
这是 Controller :
public ActionResult Index(string city, int cuisine = 0, int ChineseMaxPrice=0)
{
Return View();
}
像 int kitchen = 0 - 如果查询字符串中未设置此参数,则将默认值设置为参数
字符串城市 - 是一个应该在字符串中的参数(不是可选的)
关于asp.net - MVC 3 中的 URL 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6094880/