I'm not able to pass a double to my action (at least not in a proper way).
This is my action:
public JsonResult SomeAction(double? n = null)
{
// ...
}
And this is my ajax call:
$.ajax({
async: true,
type: 'POST',
url: '/SomeController/SomeAction',
data: {
"n": 1.5
},
success: function (data) {
...
}
});
The number 1.5 is not being passed to the action. When debugging in serverside, I'm receiving a null instead.
If I change the ajax to this:
$.ajax({
async: true,
type: 'POST',
url: '/SomeController/SomeAction',
data: {
"n": "1,5"
},
success: function (data) {
...
}
});
I do get a 1.5 in serverside.
What change in serverside do I need to do so that the first ajax call works?
Another thing that worked for me was using the first ajax call and changing the signature of the action to this:
public JsonResult SomeAction(string n = "")
{
double parsedN = Convert.ToDouble(n);
}
Of course both solutions suck