我正在使用 ASP.NET MVC3 和 C#。我有这堂课:
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["....."])
};
}
}
发送的 JSON 如下所示:
{
"ID": 401,
"Title": "MinReq",
"MinimumRequirements": {
"ID": 0,
"MinimumEducation": "Bachelors",
"MinimumGrade": "93",
"MinimumYOS": 10,
"Certifications": 1,
"Languages": "English"
}}
这是我的 c# 控制器方法的签名: [HttpPut] public ActionResult JobTitle(JobTitle jobTitle, bool doUpdate = true)
ID 和 Title 属性进来并填充了数据,一切都很好。但是 MinimumRequirements 嵌套对象为空。
我也试过这个:
[HttpPut] public ActionResult JobTitle([Bind(Prefix = "MinimumRequirements")]JobTitle jobTitle, bool doUpdate = true)
(这也不起作用)
这是 VS 调试器的屏幕截图,因此您可以了解绑定的外观:
知道为什么嵌套对象没有绑定吗?