I am using jquery to send ajax post request to my ASP MVC4 controller, and the nested object is empty.
When I post in URL encoded format using jquery.Post the data model is populated as expected, however when I try to do the same using jquery.ajax using the json format, the model received has all properties populated except for a nested property.
These are the request data captured through fiddler.
using post
Code=dfs&Name=sdf&Country.Code=PKR&Remarks=dfsdf
using json
{"Code":"dsf","Name":"sdf","Country.Code":"PKR","Remarks":"dfsdf"}
Thanks
EDIT
public class City : IKeyed<int>{
public virtual int Id { get; protected set; }
public virtual string Code { get; set; }
public virtual string Name { get; set; }
public virtual Country Country { get; set; }
public virtual string Remarks { get; set; }
public virtual bool IsActive { get; set; }
}
public class Country : IKeyed<int> {
public virtual int Id { get; protected set; }
public virtual string Name { get; set; }
public virtual string Code { get; set; }
}
$.ajax({
url: url,
type: method,
dataType: 'json',
data: data,
contentType: 'application/json; charset=utf-8'
});