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

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


The parameter name should be data, not date:

$.ajax({    type: 'POST',    url: '/Postcard/Create/Preview/',    dataType: 'json',    data: {        CardTitle: $("#CardTitle").val(),        TopicTitle: $("#TopicTitle").val(),        TopicBody: $("#TopicBody").data("tEditor").value(),        CardClose: $("#CardClose").val(),        CardFromName: $("#CardFromName").val()    },    success: function (data) {        alert('im back');        alert(data);    },    error: function (xhr, ajaxOptions, error) {        alert(xhr.status);        alert('Error: ' + xhr.responseText);    }});

which will successfully call the following controller action and the action parameter will be properly bound:

[HttpPost]public ActionResult Preview(Card card) { ... }

with the model below:

public class Card{    public string CardTitle { get; set; }    public string TopicTitle { get; set; }    public string TopicBody { get; set; }    public string CardClose { get; set; }    public string CardFromName { get; set; }}