我有一个带有嵌套类的实体模型。FSRHire 是父级,Employee 是子级:
class FSRHire {
...
public virtual Employee Employee
...
}
class Employee {
...
public string LastName {get;set;}
public DateTime DOB {get;set;}
...
}
看法:
<div class="editor-label">
@Html.LabelFor(model => model.Employee.LastName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Employee.LastName)
@Html.ValidationMessageFor(model => model.Employee.LastName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Employee.DOB)
</div>
<div class="editor-field">
@Html.TextBox(Html.IdFor(model => model.Employee.DOB).ToString(), Model.Employee.DOB.HasValue ? Model.Employee.DOB.Value.ToString("d") : "", new { @class = "date" })
@Html.ValidationMessageFor(model => model.Employee.DOB)
</div>
进入控制器的帖子不起作用。以下是请求中的数据:
...Employee.LastName=工人&Employee_DOB=01%2F01%2F1970& ...
模型活页夹很好地取了这个名字。Employee.DOB 为空。
这可能是由 DOB 字段中的下划线引起的。(Employee_DOB)。我想知道为什么会这样以及如何解决它。