Asp.Net Mvc JQuery ajax input parameters are null

Posted by Dofs on Stack Overflow See other posts from Stack Overflow or by Dofs
Published on 2010-04-01T07:41:29Z Indexed on 2010/04/01 7:43 UTC
Read the original article Hit count: 542

Filed under:
|

Hi, I am trying to post some data with jQuery Ajax, but the parameters in my Ajax method are null.

This is simple test to send data:

 var dataPost = { titel: 'titel', message: 'msg', tagIds: 'hello' };
        jQuery.ajax({
            type: "POST",
            url: "Create",
            contentType: 'application/json; charset=utf-8',
            data: $.toJSON(dataPost),
            dataType: "json",
            success: function(result) {
                alert("Data Returned: ");
            }
        });

And my Ajax method looks like this:

[HttpPost]
public ActionResult Create(string title, string message, string tagIds)
{... }

There is something basic wrong with the data I send, but I can't figure out what. All the time the title, message and tagIds are null, so there is something wrong with the encoding, I just don't know what.

Note: The jQuery.toJSON is this plugin

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about jquery-ajax