I've noticed that when using $.post() in jquery that the default contentType is application/x-www-form-urlencoded - when my asp.net mvc code needs to have contentType=application/json
(See this question for why I must use application/json: http://stackoverflow.com/questions/2792603/aspnet-mvc-why-is-modelstate-isvalid-false-the-x-field-is-required-when-that)
How can I make $.post() send contentType=application/json? I already have a large number of $.post() functions, so I don't want to change to $.ajax() because it would take too much time
If I try
$.post(url, data, function(), "json")
contentType: "application/json; charset=utf-8"
I think you may have to
1.Modify the source to make $.post always use JSON data type as it really is just a shortcut for a pre configured
3.You could overwrite the
$.post function with your own implementation via monkey patching.
The JSON datatype in your example refers to the datatype returned from the server and not the format sent to the server.