Asp.net mvc ASP.NET MVC-逗号分隔双精度作为控制器操作的参数

Asp.net mvc ASP.NET MVC-逗号分隔双精度作为控制器操作的参数,asp.net-mvc,parameters,double,comma,controller-action,Asp.net Mvc,Parameters,Double,Comma,Controller Action,我有以下控制器操作: public ActionResult AjaxQuantity(int-productId=0,double-quantity=0d,int-periodId=0) { ... } 以及适当的ajax请求: 函数数量(产品ID、数量、周期ID){ $.ajax({ url:“@(url.Action(“AjaxQuantity”)”, cache:false, 键入:“获取”, 数据:{productId:productId,quantity:quantity,peri

我有以下控制器操作:

public ActionResult AjaxQuantity(int-productId=0,double-quantity=0d,int-periodId=0)
{
...
}
以及适当的ajax请求:

函数数量(产品ID、数量、周期ID){
$.ajax({
url:“@(url.Action(“AjaxQuantity”)”,
cache:false,
键入:“获取”,
数据:{productId:productId,quantity:quantity,periodId:periodId},
错误:函数(){
Server503();
}
});
};
此外,还要使用逗号作为小数分隔符的区域性

例如,当我使用“12,34”作为数量执行ajax请求时,在控制器操作中,我得到的数量为1234d

若我将ajax请求的类型更改为“POST”,那个么我将得到操作中所需的数量,即12,34d


GET请求发生了什么?看起来就像GET请求区域性中没有使用一样(逗号是简单的剥离)

问题是,
,“
是一个保留的URI字符
,因此您不能在GET参数中使用它

POST参数作为请求体发送,因为
,“
也可以在那里使用

从 2.2. 保留字符

   Many URI include components consisting of or delimited by, certain
   special characters.  These characters are called "reserved", since
   their usage within the URI component is limited to their reserved
   purpose.  If the data for a URI component would conflict with the
   reserved purpose, then the conflicting data must be escaped before
   forming the URI.

      reserved    = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                    "$" | ","

即使您找到了解决方案,我也建议您接受参数作为字符串,并让.Net为您处理区域性内容。试图依靠浏览器来正确实现这一点恐怕会让您失望。字符串参数当然是可以接受的解决方案。但是为什么MVC不能为我的双类型参数做这项工作呢?MVC为POST请求工作,为什么不为GET请求工作?有什么不同?我同意你的看法,但在请求中逗号编码为“%2c”,所以MVC为我解析“12%2c34”并不是什么大问题。