An example with misaligned validation message:
To amend that, we could do this:
<div class="editor-label"> @Html.LabelFor(model => model.CountryId) </div> <div class="editor-field" > <table> <td> @Html.AjaxComboBoxFor(x => x.CountryId, null, "/Home/CountryLookup", "/Home/CountryCaption") </td> <td> @Html.ValidationMessageFor(x => x.CountryId) </td> </table> </div>
Using that, the unobtrusive validation message's alignment will be rendered properly
But that approach will eventually violate DRY principle, so we need to amend our approach. We will use templated razor delegate
@{ Func<dynamic, object> align = @<table> <tr> @foreach (var s in item) { <td>@s</td> } </tr> </table>; }
To use:
<div class="editor-label"> @Html.LabelFor(model => model.CountryId) </div> <div class="editor-field" > @align( new[]{ Html.AjaxComboBoxFor(x => x.CountryId, null, "/Home/CountryLookup", "/Home/CountryCaption"), Html.ValidationMessageFor(x => x.CountryId) }) </div>
No comments:
Post a Comment