根据模型中定义的验证,有没有办法突出显示/设置DisplayFor或/和DisplayNameFor字段?
这是一个强类型的局部视图,我正在使用umbraco 7
@inherits UmbracoViewPage<MyProject.Models.ImportViewModel>
@{
Layout = "~/Views/Master.cshtml";
}
<table class="list">
@foreach (var item in Model.Items)
{
var categories = (IEnumerable<MyProject.Models.Category>)ViewData["categories"];
<tr class="list-item">
<td>
<table>
<tbody>
<tr>
<td colspan="3">
<h2>
(@Html.DisplayFor(modelItem => item.Ref))
@Html.DisplayFor(modelItem => item.Title)
</h2>
</td>
<td>
<label class="auto">@Html.DisplayNameFor(model => item.Status)</label>
@Html.DisplayFor(modelItem => item.Status)<br /><br />
@Html.ActionLink("Approve", "Approve", new { id = item.Id })
</td>
</tr>
<tr>
<td>
<label>Category:</label> @Html.DisplayFor(modelItem => categories.First(m => m.Id == item.CategoryId).Name)
</td>
<td>
<label>@Html.DisplayNameFor(model => item.Description)</label>
@Html.DisplayFor(modelItem => item.DescriptionShort)
</td>
</tr>
</tbody>
</table>
</td>
</tr>
}
</table>
我在控制器中有这个:
List<MyProject.Models.Import> items = (List<MyProject.Models.Import>)Session["sesimp"];
return PartialView("ItemList", new ImportViewModel { Items = items });
我想根据模型中定义的字段验证突出显示不正确的字段。
因此,例如,如果未选择 category 且在模型中定义为<),则列表上的此字段分配了不同的css类和/或可能显示错误消息。如果 Ref 为空,标题或描述包含无效字符等,则相同。
如果项目未通过验证,我还需要禁用批准链接。
怎么做?