【发布时间】:2023-03-30 02:04:02
【问题描述】:
我好像在光天化日之下纠结:
我有一个模型类
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; }
}
Views 被列出来,所有的显示都正确,但是在回发 FlightHours 属性是 null,为什么引擎没有正确初始化 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>
【问题讨论】:
-
你不需要
Html.Partial(..之前的第二个代码段中的@符号,因为你已经在C#上下文中了
标签: asp.net-mvc-3 list editview