Deserialization of the form does not work


I have an asynchonous httpPost that serializes my form data and commits it to my controller. There I try to get my form data serialized into my view model class but all the values are null or have the default value assigned.

public ActionResult GetSalesData(string vmString)
    -use the data to select some other data
    return new JsonResult { Data = d, JsonRequestBehavior = JsonRequestBehavior.AllowGet };

For the serialization I tried so far these two ways:


    { vmString: $('form').serialize() }




    { vmString: JSON.stringify($('form')) }



To deserialize, I tried:

m = (StatisticsViewerViewModel)new JsonSerializer().Deserialize(new System.IO.StringReader(vmString), typeof(StatisticsViewerViewModel));
m = (StatisticsViewerViewModel)new JsonSerializer().Deserialize(new System.IO.StringReader(vmString), vmString.GetType());
m = JsonConvert.DeserializeObject<StatisticsViewerViewModel>(vmString);

DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(StatisticsViewerViewModel));
m = (StatisticsViewerViewModel) ser.ReadObject(stream);

I checked that all my fields are inside the form:

 @using (Html.BeginForm())
   some partial views containing some fields, all using the same model..

I also checked that the used View Model as well as all nested models do have an empty constructor.

Are there different ways to de-/serialize the form data? And what else could I check to make sure everything is as it should be?

  • EDIT -


public class StatisticsViewerViewModel
    public String BreadcrumbName { get; set; }
    public String ActionName { get; set; }
    public StatisticsType Type { get; set; }
    public DropDownListModel DataSourceList { get; set; }
    public MultiSelectionModel Dataset { get; set; }
    public SalesViewModel SalesVm { get; set; }
    //public EventsViewModel EventsVm { get; set; }
    public ChartExportOptions ExportOptions { get; set; }

    public StatisticsViewerViewModel()
        DataSourceList = new DropDownListModel();
        Dataset = new MultiSelectionModel();
        SalesVm = new SalesViewModel();
        ExportOptions = new ChartExportOptions();

    public enum StatisticsType

Nested ViewModels

public class SalesViewModel
    public SalesDisplayOptions DisplayOptions { get; set; }
    public RadioButtonModel DisplayModes { get; set; }      // Volume, Value, ..
    public RadioButtonModel SeriesTypes { get; set; }       // Line, Bar, ..

    public SalesViewModel(bool initialize = false)
        if (initialize) { Initialize(); }

public class SalesDisplayOptions
    public DisplayMode Mode { get; set; }
    public SeriesType Type { get; set; }
    public bool ShowAverage { get; set; }
    public bool ShowTargetLine { get; set; }

    public enum SeriesType
        Lines, ...

    public enum DisplayMode
        Value, ...


A relevant point might be that the post is fired by kendoChart. Here the interesting block inside the view:

<div id="chart"></div>
@<script type="text/javascript">
             dataSource: new{
                 transport: {
                     read: {
                         url: actionUrl,
                         data: { vmString: $('form').serialize() },
                         dataType: "json",
                         contentType: "application/json; charset=utf-8"
                 sort: ...

To check whether the problems are related to the kendoChart-Object, I testwisely implemented a manual POST:

<div class="round-corner-bottom-right">
        <button id="send-form" type="button">
            <span class="button-label">Send Form Data</span>

@<script type="text/javascript">

     $('document').ready(function () {

        $('#send-form').on('click', function () {

             var data = $('form').serialize();

                 type: "POST",
                 url: actionUrl,
                 data: data,
                 cache: false,
                 success: function (returnData) {

     }); // document ready

The problem does not persist in this scenario, all values are set as expected. So there seems to be a problem with the kendoChart-methode.

Have you tired using allowing default model binder to handle it rather than trying to deserialize and managing it yourself?


public ActionResult GetSalesData(string vmString)

becomes this

public ActionResult GetSalesData(MyModel vmString)