我有一个表单,它使用该POST
方法将数据发送到我的控制器上的Create
操作(用 注释)。[HttpPost]
动作签名采用Visit
. 问题是只有一些属性Visit
被填充,尽管所有属性都被填充在视图的屏幕上。仅填充将数据输入到文本框中的属性。下拉列表中的任何值都没有传递给模型。
有什么想法吗?谢谢!
MVC 4 测试版。
更新 1-视图中使用的表单...
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Visit</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Visit.VisitDate)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Visit.VisitDate, new { @class = "editor-field-medium" })
@Html.ValidationMessageFor(model => model.Visit.VisitDate)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Visit.NPN)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Visit.NPN, new { @class = "editor-field-medium" })
@Html.ValidationMessageFor(model => model.Visit.NPN)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Visit.AppointmentTypeId)
</div>
<div class="editor-field"> @* THIS DOES NOT GET POPULATED WHEN PASSED TO THE ACTION*@
@Html.DropDownList("AppointmentTypeId", String.Empty)
@Html.ValidationMessageFor(model => model.Visit.AppointmentTypeId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Visit.EducationId)
</div>
<div class="editor-field"> @* THIS DOES NOT GET POPULATED WHEN PASSED TO THE ACTION*@
@Html.DropDownList("EducationId", String.Empty)
@Html.ValidationMessageFor(model => model.Visit.EducationId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Visit.PsychologistId)
</div>
<div class="editor-field"> @* THIS DOES NOT GET POPULATED WHEN PASSED TO THE ACTION*@
@Html.DropDownList("PsychologistId", String.Empty)
@Html.ValidationMessageFor(model => model.Visit.PsychologistId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Visit.PsychometristId)
</div>
<div class="editor-field"> @* THIS DOES NOT GET POPULATED WHEN PASSED TO THE ACTION*@
@Html.DropDownList("PsychometristId", String.Empty)
@Html.ValidationMessageFor(model => model.Visit.PsychometristId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Visit.PostDoctoralId)
</div>
<div class="editor-field"> @* THIS DOES NOT GET POPULATED WHEN PASSED TO THE ACTION*@
@Html.DropDownList("PostDoctoralId", String.Empty)
@Html.ValidationMessageFor(model => model.Visit.PostDoctoralId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Visit.BehavioralObservations)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Visit.BehavioralObservations)
@Html.ValidationMessageFor(model => model.Visit.BehavioralObservations)
</div>
<p>
<input type="submit" value="Create Visit" />
</p>
</fieldset>
}