1

我有以下控制器操作:

public ActionResult AjaxQuantity(int productId = 0, double quantity = 0d, int periodId = 0)
{
   ...
}

和适当的ajax请求:

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”作为数量进行 ajax 请求时,在控制器操作中我得到的数量为 1234d。

如果我将 ajax 请求的类型更改为“POST”,那么我会在操作中获得所需的数量为 12,34d。

GET 请求发生了什么?看起来就像在未使用的 GET 请求文化中一样(逗号很简单)。

4

1 回答 1

1

问题是这','是一个保留的 URI 字符,因此您无法在 GET 参数中使用它。

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

来自统一资源标识符 (URI):通用语法 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    = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                    "$" | ","
于 2014-05-15T18:53:33.327 回答