Pass object from JSON into MVC Controller - its always null ?

Posted by SteveCl on Stack Overflow See other posts from Stack Overflow or by SteveCl
Published on 2011-01-11T09:46:58Z Indexed on 2011/01/11 9:53 UTC
Read the original article Hit count: 191

Filed under:
|

Hi

I have seen a few questions on here related to the a similar issue, I have read them, followed them, but still i have the same problem.

I am basically creating an object in javascript and trying to call a method on the controller that will return a string of html. Not JSON.

I've been playing around with dataType and contentType but still no joy. So apologies if the code snippets are a bit messy.

Build the object in JS.

function GetCardModel() {
    var card = {};
    card.CardTitle = $("#CardTitle").val();
    card.TopicTitle = $("#TopicTitle").val();
    card.TopicBody = $("#TopicBody").data("tEditor").value();
    card.CardClose = $("#CardClose").val();
    card.CardFromName = $("#CardFromName").val();
    return card;
}

Take a look at the object - all looks good and as it should in JSON.

var model = GetCardModel();
alert(JSON.stringify(GetCardModel()));

Make the call...

$.ajax({
            type: "POST",
            url: "/Postcard/Create/Preview/",
            dataType: "json",
            //contentType: "application/json",
            date: GetCardModel(),
            processData: true,
            success: function (data) {
                alert("im back");
                alert(data);
            },
            error: function (xhr, ajaxOptions, error) {
                alert(xhr.status);
                alert("Error: " + xhr.responseText);
                //alert(error);
            }
        });

Always when I step into the controller, the object is ALWAYS there, but with null values for all the properties.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about asp.net-mvc-2