views:

24

answers:

1

I've got a custom Editor Template that is essentially:

<div id="control">
<%: Html.DropDownListFor(model => model.Day, Model.Days)%>
<%: Html.DropDownListFor(model => model.Month, Model.Months)%>
<%: Html.DropDownListFor(model => model.Year, Model.Years)%>
</div>

Whilst my validation is successful/fine with this control (ValidationMessageFor works) I have been unable to find how to highlight the control when validation fails (e.g. with a TextBoxFor the textbox border goes red if validation fails)

Does anyone know how I can add this behaviour with a custom editor template please?

A: 

Interesting question. If you can detect a validation error, then you should be able to apply the appropriate class. Something like this, substitute in your own field name:

 <div id = "control" class="<%=ViewData.ModelState.IsValidField("DateField") ? "" : "validation-error" %>">
Clicktricity
Cheers, exactly the behaviour I was after (though I used ViewData.ModelState.IsValid to encompass the whole control rather than a single field)
S L