I've a collection of Cards in my EmployeeMasterA class, I'm not sure what is the correct way to append the collection in FormData object. What I want something like this :
var data = new FormData();
data.append('Cards[0].CardId', 1);
data.append('Cards[0].CardTitle', "Credit");
data.append('Cards[1].CardId', 2);
data.append('Cards[1].CardTitle', "Debit");
and this is my ajax request:
$.ajax({
url: '/EmployeeMasterA/Create',
data: data,
type: 'POST',
contentType: false,
processData : false,
success: function (result) {
if (result.Success == "1") {
}
}
});
and my controller :
[HttpPost]
public ActionResult Create(EmployeeMasterA employeeMasterA)
{
//get data and perform logics
}
EmployeeMasterA Class :
public class EmployeeMasterA
{
public string EmployeeCode { get; set; }
public virtual ICollection<Cards> Cards { get; set; }
}
EmployeeMasterA contains collection of Cards, here is the Cards Class :
public class Cards
{
public int CardId { get; set; }
public string CardTitle { get; set; }
}
How do I append the collection of Cards in the FormData object? So that it binds correctly with the EmployeeMasterA class.
Update
When I take a look in debug mode, the Cards collection is null, Why?