I’m using ASP.NET MVC3 and C#. I have this class:
public class JobTitle
{
public int ID { get; set; }
public string Title { get; set; }
public MinimumRequirements MinimumRequirements;
public JobTitle(DataRow row)
{
ID = Utilities.SafeInt(row["JobTitle_ID"]);
Title = Utilities.SafeString(row["Job_Title"]);
MinimumRequirements = new MinimumRequirements()
{
Certifications = Utilities.SafeInt(row["....."]),
ID = Utilities.SafeInt(row["....."]),
Languages = Utilities.SafeString(row["....."]),
MinimumEducation = Utilities.SafeString(row["....."]),
MinimumGrade = Utilities.SafeString(row["....."]),
MinimumYOS = Utilities.SafeInt(row["....."])
};
}
}
And the JSON being sent looks like this:
{
"ID": 401,
"Title": "MinReq",
"MinimumRequirements": {
"ID": 0,
"MinimumEducation": "Bachelors",
"MinimumGrade": "93",
"MinimumYOS": 10,
"Certifications": 1,
"Languages": "English"
}}
Here’s the signature of my c# controller method:
[HttpPut]
public ActionResult JobTitle(JobTitle jobTitle, bool doUpdate = true)
The ID and Title properties come in and populated with data, all fine. But the MinimumRequirements nested object comes in null.
I also tried this:
[HttpPut]
public ActionResult JobTitle([Bind(Prefix = “MinimumRequirements”)]JobTitle jobTitle, bool doUpdate = true)
(that didn’t work either)
Here’s a screenshot from the VS debugger so you know how the binding looks:

Any idea why the nested object isn’t binding?
In your
JobTitleclassMinimumRequirementsmust be aproperty, not afield.So replace:
with:
Remember that the default model binder operates only on properties, not on fields.
Also from what I can see your
JobTitlemodel doesn’t have a parameterless constructor so you cannot use it as action argument because the default model binder won’t know how to instantiate it. So make sure that in addition to the constructor that takes aDataRowyou also have a parameterless constructor or you will have to write a custom model binder for this type if you want it to appear as action parameter.