Take the 2-minute tour ×

The Route is:

    "Ajax", // Route name
    "BizTalk/Services/{action}", // URL with parameters
    { // Parameter defaults
     controller = "BizTalk"

My Controller is:

public JsonResult AjaxTest(string s, int i, bool b)
   return Json("S: " + s + "," + "I: " + i + "," + "B: " + b);

My jQuery Code:

$(document).ready(function() {
   $("#btn_test").click(function() {
    var s = "test";
    var i = 8;
    var b = true;
     type: "POST", cache: false,
     url: "/BizTalk/Services/AjaxTest",
     data: { i: i, s: s, b: b },
     dataType: "json",
     success: function(msg) {
share|improve this question

4 Answers 4

up vote 6 down vote accepted

This post explains the problem and a possible solution (similar to how @Erv has explained).

If you remove contentType: "application/json; charset=utf-8" from your call to jQuery.ajax the default content type (form-urlencoded) will be used and the json data you have specified as your data parameter (data: { i: i, s: s, b: b }) will be mapped correctly to your action parameters....so unless you really want to send json data just remove the contentType and you will be fine.....

share|improve this answer
removing contentType worked. but i want to know: 1-if removing contentType is a solution or little trick. 2- works on every browsers. 3- and whats wrong about it? I was using the above codes on my WebForm project just fine! –  desmati May 8 '10 at 8:24
@desmati no this is not a trick...the data is just being wrapped up as fields of the form that is posted by the ajax call, the field names are then correctly mapped/bound to the parameters of your action by the framework –  Simon Fox May 10 '10 at 2:19
Is there any way to write a custom parameter mapping? –  desmati May 12 '10 at 8:19

ASP.NET MVC does not automatically map incoming JSON data into action method parameters.

See the following article for a solution to add that capability:


Also, I think your jQuery call does not actually send JSON although that seems to be what you want it to do. jQuery will not automatically convert the data object to JSON. You need to convert it to JSON yourself with something like json2.js

share|improve this answer
the incoming data isn't json here, you're wrong. –  zerkms May 7 '10 at 2:30
contentType: "application/json; charset=utf-8" sets the request header to indicate that the POST contains JSON. –  Erv Walter May 7 '10 at 13:09
Thank You. but I prefer not to use mvc2. –  desmati May 8 '10 at 8:09

how did you get that "jquery ... does not pass parameters"? have you tried to sniff the request with firebug?

you're sending data in POST body but trying to access them in regular way (with using action arguments) like GET.
all POST data is in Request.Form or you have to handle it by binding to some custom ViewModel.

share|improve this answer
The Request.Form[0] is: {"i":"8","b":"test","b":"true"} –  desmati May 8 '10 at 8:08
so? and what did you expect to see there? –  zerkms May 8 '10 at 9:42

Erm, might be wrong but you are passing in the jQuery i, s, b but in the action you have s, i,b .

The order must be correct for jQuery posts.


Here is how I use jQuery posts;


        $.post("/Articles/jQueryAddComment", { commentText: commentText, id: id, type: commentType }, function(returnedHTML) {
//Do something with the returned html.

In my controller

        public ActionResult jQueryAddComment(string commentText, int id, string type)
//do some stuff
                return PartialView("CommentList", fvm);
share|improve this answer
omg %) post data doesn't go through routing, so you cannot handle them as parameters of action method. –  zerkms May 7 '10 at 2:31
@zerkms, unsure what your comment actually means. are you saying that you can't use routing in a jQuery post? you may be right i've never explored the possibility. if that's not what your saying could you please elaborate? –  griegs May 7 '10 at 4:33
thanks griegs, bit The order does not matters. and i'm using $.ajax. –  desmati May 8 '10 at 8:12

Your Answer


