我当前的网址是这样的=> 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

字符串城市-是应该在字符串中的参数(非可选)

10-07 12:56