如何解决MVC 3中的URL路由
| 我当前的网址是这样的=> 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
);
这是控制器:
public ActionResult Index(string city,int cuisine = 0,int ChineseMaxPrice=0)
{
Return View();
}
像int Cuisine = 0-如果未在querystring中设置此参数,则将默认值设置为parameter
字符串城市-是应该在字符串中的参数(非可选)
,尝试添加添加相应的路由:
routes.MapRoute(
\"Restaurants\",\"Restaurants/{city}\",new { controller = \"Restaurants\",action = \"Index\",city = UrlParameter.Optional }
);
它将映射到Restaurants
控制器上的Index
动作:
public ActionResult Index(string city)
{
...
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。