I have an object declared in my javascript which I would like to send to my controller. The object is of type VMInterface which looks like:
public class VMInterface
{
public string Name { get; set; }
public int SourceID { get; set; }
public int ProjectID { get; set; }
public string Description { get; set; }
public VMConnection VMConnection { get; set; }
public List<VMInteraction> Interactions { get; set; }
}
public class VMConnection
{
public string Username { get; set; }
public string Password { get; set; }
public string Connection { get; set; }
}
public class VMInteraction
{
public string Name { get; set; }
public List<VMField> Fields { get; set; }
}
public class VMField
{
public string InputOutput { get; set; }
public string Name { get; set; }
public int DataTypeID { get; set; }
}
My controller:
[HttpGet]
public JsonResult UpdateVM(VMInterface vm)
{
return null;
}
My call to the controller:
$.ajax({
url: '/Admin/UpdateVM',
type: 'GET',
data: {
Name: "Test Name",
Description: "Test Desc",
SourceID: 1,
ProjectID: 4,
VMConnection: {
Connection: "IPAddress goes here",
Username: "Username",
Password: "Password"
},
Interactions: [{
Name: "Method",
Fields: [{
InputOutput: "INPUT OR OUTPUT HERE",
Name: "DROP LOCATION HERE",
DataTypeID: 1
}],
}]
},
success: function (response) {
//Do nothing
}
});
I have double checked that all the field names match up and that the properties inside my VMInterface class are all public with { get; set; }. My call is hitting my controller ok and all of the top level (ei Name, Description, SourceID and ProjectID) fields map correctly. However for my VMConnection and Interactions field the information is not being populated.
Is there anything I'm missing to get these mapped correctly?


data: JSON.stringify{ vm: data }and setcontentType: 'application/json',or alternatively name the properties to match your model using dot notation e.g.VMConnection.Connection: 'IPAddress goes here'and `Interactions[0].Name: 'Method' etc{ vm: yourData }as per my comment