I need some help with the hereunder please. I have these 2 models and the method I will be using them in hereunder.
public class RoleModel
{
public string Name { get; set; }
public string Description { get; set; }
public List<PermissionGroupModel> PermissionGroups { get; set; }
}
public class PermissionGroupModel
{
public int PermissionGroupID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
[HttpPost]
public bool CreateRole(RoleModel r){
//code goes here
}
I am trying to post data to the CreateRole() method via AJAX and using a debug break to inspect the 'r' parameter to see if the model is getting populated. This is the AJAX call I am using to test it out.
$.ajax({
type: "POST",
url: "/BackOffice/CreateRole",
data: {"Name": "Test Name", "Description": "Test Desc", "PermissionGroups": ["Name": "Group Name", "Description": "Test Desc"]},
success: function (data) {},
complete: function (data) {}
});
When the request is made and I inspect the parameter in visual studio. The RoleModel Name and Description Keys are populated and PermissionGroups Count is 1 but the keys in PermissionGroups are not being populated.
Can anyone suggest any way I can pass a JSON object with a list of objects in it.
Thanks in advance.