光天化日之下,我似乎很纠结:
我有一个模型类
public class Pilot
{
//.. other prop-s escaped
private List<FlightHoursEntry> FlightHours { get; set; }
}
public class FlightHoursEntry
{
public string Description { get; set; }
public int Hours { get; set; }
}
视图列在下面,所有显示都正确,但是在回发时 FlightHours 属性为空,为什么引擎没有正确初始化 Pilot 的对象?
在 PilotEditView 我正在使用@Html.EditorFor(model => model.FlightHours)
FlightHoursCollectionView 是:
@model List<FlightHoursEntry>
@for (int i = 0; i < Model.Count; i++){
FlightHoursEntry fh = Model[i];
@Html.Partial("~/../FlightHoursEntryEditView.cshtml", fh);}
我也试过这种方式 @Html.EditorFor(model=>model[i], "FlightHoursEntryEditView", fh)
和简单的 FlightHoursEntryEditView
@model PumaMvc.Models.BusinessObjects.Copa.FlightHoursEntry
<div class="editor-label">
@Html.LabelFor(model => model.Hours)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Hours)
@Html.ValidationMessageFor(model => model.Hours)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>