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 パラメーターは、','そこでも使用できるため、リクエスト本文として送信されます。

Uniform Resource Identifiers (URI)から: Generic Syntax 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 に答える