I am posting data to a controller stringified by knockout:
var data = ko.toJSON(viewModel);
$.ajax({
type: 'POST',
url: '@Url.Action("Action")',
data: { data: data },
dataType: 'json'
....
})
Then server-side, I try to deserialize the data with JsonConvert.
var viewModel = JsonConvert.DeserializeObject<ViewModel>(data,
new JsonSerializerSettings
{
DateTimeZoneHandling = DateTimeZoneHandling.Local,
DateFormatHandling = DateFormatHandling.IsoDateFormat
});
This fails if data contains null values (serialized as "NaN"), looking like this:
"MyField":"NaN"
Without null values, it works fine.
I tried adding NullValueHandling = NullValueHandling.Include/Ignore to the serializer settings, both without success.