路由器提供商MVC

问题描述 投票:1回答:1

如果我想强制路由映射并允许数量值为十进制,我应该如何使用正则表达式更改它?

routes.MapLocalizedRoute("AddProduct-Catalog",
                            "addproduct/catalog/{productId}/{shoppingTypeId}/{quantity}",
                            new { controller = "Shopping", action = "AddProduct_Catalog"},
                            new { productId = @"\d+", shoppingTypeId = @"\d+", quantity=@"\d+" },
                            new[] { "BBC.Web.Controllers" });

目前,如果我通过addproduct / catalog / 34/1/5 OK,如果我通过

addproduct / catalog / 34/1 / 5.5 NO

asp.net-mvc model-view-controller
1个回答
0
投票

尝试使用查询字符串而不是int / decimal / float表示小数,所以它看起来像

addproduct/catalog/34/1/?quantity=5.5

并在控制器中解析它

public ActionResult Catalog(string quantity){
   var myval = (decimal)quantity;
}
© www.soinside.com 2019 - 2024. All rights reserved.