1

I have the following controller action:

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

and appropriate ajax request:

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

Also, have a culture with a comma as decimal separator.

When I do ajax request with, for example, "12,34" as quantity, inside controller action I get quantity as 1234d.

If I change type of ajax request to "POST", then I get desired quantity inside action as 12,34d.

What's happening with GET request? Look's like in GET request culture not used (comma is simple stript off).

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 1
    Even if you find a solution I would recommend accepting the parameter as a string and letting .Net handle the culture stuff for you. Trying to count on browsers to implement this correctly is just going to leave you disappointed I'm afraid. – Spencer Ruport May 15 '14 at 18:14
  • String parameter, of course, acceptable as solution. But why MVC can't do this work for me for double type parameter? MVC do work for POST request, why not for GET request? What's the differ? –  May 15 '14 at 18:45

1 Answers1

1

The thing is that ',' is a reserved URI character so you are not able to use it in GET parameters.

POST parameters are send as request body, because of that ',' could be used there as well.

From Uniform Resource Identifiers (URI): Generic Syntax 2.2. Reserved Characters

   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    = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                    "$" | ","
Dmitry Zaets
  • 3,289
  • 1
  • 20
  • 33
  • I agree with You, but comma encoded as "%2c" in request, so it's not a big problem for MVC to parse "12%2c34" for me. –  May 15 '14 at 18:59