Here is a snippet of my C# code:
Model:
namespace WebInventory.Models
{
[DataContract]
public class PostbackList
{
[DataContract]
public class Field
{
public int ID;
public string Name;
public int DataTypeID;
public bool Checked;
}
[DataMember]
public int TypeID;
[DataMember]
public IList<Field> Fields;
[DataMember]
public IList<IList<string>> Values;
#region Non DataMember
public IList<int> UsedFieldsID;
#endregion
}
}
Controller:
public class ListController : JsonController
{
[HttpPost]
public ActionResult GetList(PostbackList data)
{
<...>
}
}
When sending the JSON object below:
{"TypeID":16,"Fields":[{"ID":42,"Name":"","DataTypeID":0,"Checked":true},{"ID":43,"Name":"","DataTypeID":0,"Checked":true},{"ID":44,"Name":"","DataTypeID":0,"Checked":true}],"Values":null}
using this AJAX call:
$.ajax({
url: url
, type: 'POST'
, dataType: 'json'
, contentType: 'application/json; charset=utf-8'
, data: JSON.stringify(parameter)
, xhrFields: {
withCredentials: true
}
})
.done(function (data) {
fillTemplate(data);
});
I have encountered an issue where data
appears to be uninitialized in the MVC GetList
. I tried using arrays instead of IList but it didn't resolve the problem.
I am currently unsure what the cause of this issue may be.