首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ASP.NET MVC -逗号分隔为控制器动作的参数

ASP.NET MVC -逗号分隔为控制器动作的参数
EN

Stack Overflow用户
提问于 2014-05-15 18:08:41
回答 1查看 1.2K关注 0票数 1

我有以下控制器操作:

代码语言:javascript
复制
public ActionResult AjaxQuantity(int productId = 0, double quantity = 0d, int periodId = 0)
{
   ...
}

和适当的ajax请求:

代码语言:javascript
复制
function Quantity(productId, quantity, periodId) {
    $.ajax({
        url: "@(Url.Action("AjaxQuantity"))",
        cache: false,
        type: "GET",
        data: { productId: productId, quantity: quantity, periodId: periodId },
        error: function () {
            Server503();
        }
    });
};

此外,还有一个以逗号作为小数点分隔符的区域性。

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

如果我将ajax请求的类型更改为"POST",那么在12,34d的内部操作就会得到所需的数量。

GET请求是怎么回事?看上去就像在GET请求区域性中没有使用(逗号是简单的stript off)。

EN

回答 1

Stack Overflow用户

发布于 2014-05-15 18:53:33

问题是,',' 是一个保留的URI字符,所以您不能在GET参数中使用它。

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

来自Uniform Resource Identifiers (URI): Generic Syntax 2.2。保留字符

代码语言:javascript
复制
   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    = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                    "$" | ","
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23685671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档