asp.net - MVC 3 中的 URL 路由

标签 asp.net asp.net-mvc url url-routing

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

相关文章:

c# - WCF 使用 SOAP 1.2,即使 MessageVersion 是 Soap11WSAddressing10

c# - Autofac + Automapper + 自定义 ValueResolver

c# - 如何使用 DataAnnotations 检查属性是否仅匹配字符串数组

java - PrettyFaces 不适用于 Struts 2

php - 使用 base64 编码的字符串 URL

actionscript-3 - AS3 URL 字符串 -> URLRequest

c# - 单击链接时,asp.net 显示一个带有“确定”按钮的框

c# - 更改 Gridview 页面后,Gridview 不会重新绑定(bind)数据

c# - 委托(delegate)使用 : Business Applications

c# - Cookie 身份验证提前到期