I am serializing form data and adding an extra object of users into it.
Jquery code:
....
var users= getUsers();
var formData = $("#form").serializeArray();
formData.push({ name: 'Users', value: users});
$.ajax({
url: "/ControllerName/ViewName",
type: "POST",
contentType: "application/x-www-form-urlencoded; charset=UTF-8"
data: formData
});
....
function getUsers() {
var users= [];
users.push( new Object({
Name: "User 1",
}));
return users;
}
C# Model
public class File
{
public string Name { get; set; }
public int Id { get; set; }
public List<Users> Users { get; set; }
}
public class Users
{
public string Name { get; set; }
}
When the call hits server side controller action, the Users list is always empty (Count of 0). I have tried stringify and sending as Json but that didn't help either. I am using ASP.NET MVC 5 on server side.
What am I doing wrong?
edit What I am having trouble with is trying to push a list of objects into the formData (in this case users). If I push a boolean it deserializes fine on the server side.