Is there any way to highlight/ style DisplayFor or/and DisplayNameFor fields depending on validation defined in the model?
It is in a strongly typed partial view and I'm using 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>
I have this in my controller:
List<MyProject.Models.Import> items = (List<MyProject.Models.Import>)Session["sesimp"];
return PartialView("ItemList", new ImportViewModel { Items = items });
I want to highlight fields which are not correct based on the field validation defined in the model.
So for example if category is not selected and it is defined as required in model) then this field on the list has different css class assigned and/or possibly display error message. Same if Ref is empty, Title or Description contains invalid characters etc.
Also I need to disable Approve link if the item didn't pass validation.
How to do it?