【发布时间】:2016-03-03 05:40:29
【问题描述】:
我有一个视图,我在其中循环渲染了部分视图。有一个列表,部分视图与列表中的每个项目绑定。输入值后,我没有在控制器上获取列表的值。
这是我的看法:
<table id="resourceRequirement" class="table" width="100%" border="0">
<thead>
<tr style="background-color:#dfdfdf;">
<td><div align="center">PRIORITY</div></td>
<td><div align="center">SYSTEM RESOURCE / COMPONENT</div></td>
<td><div align="center">RECOVERY TIME OBJECTIVE</div></td>
</tr>
</thead>
<tbody>
@foreach (var item in Model.ResourceRequirement)
{
@Html.Partial("~/Views/Shared/_ResourceRequirement.cshtml", item)
}
</tbody>
</table>
这是我的部分观点:
@model DisasterManagementSystem.Models.BusinessImpactAnalysis.ResourceRequirement
<tr>
<td>
@Html.TextBoxFor(m => m.priority)<br />
<div style="color:red;">
@Html.ValidationMessageFor(model => model.priority)
</div>
</td>
<td>
@Html.TextBoxFor(m => m.systemresource)<br />
<div style="color:red;">
@Html.ValidationMessageFor(model => model.systemresource)
</div>
</td>
<td>
@Html.TextBoxFor(m => m.receveryTime)<br />
<div style="color:red;">
@Html.ValidationMessageFor(model => model.receveryTime)
</div>
</td>
</tr>
这是我的清单:
public List<ResourceRequirement> ResourceRequirement { get; set; }
课程在这里:
public class ResourceRequirement
{
[Required(ErrorMessage = "*")]
public string priority { get; set; }
[Required(ErrorMessage = "*")]
public string systemresource { get; set; }
[Required(ErrorMessage = "*")]
public string receveryTime { get; set; }
}
当我尝试从帖子中的模型获取列表时,请告知我将列表设为空。
【问题讨论】:
-
也许渲染这个视图的控制器动作没有在模型中提供任何值?
-
在填写详细信息后最初呈现空白表单,它不返回值。只返回 null
-
你也可以显示控制器代码吗?
标签: .net asp.net-mvc-5