view - Custom Editor template based on ViewModel Dataannotation attribute MVC4 -
what want automatically add image span after input textboxes if [required] attribute decorates viewmodel property integer, double, string, date etc
for example, viewmodel might like
public class myviewmodel { [required] public string name { get; set; } }
and view like
@html.editorfor(model => model.name) @html.validationmessagefor(model => model.name)
and output like
<input id="name" class="text-box single-line" type="text" value="" name="name" data-val-required="the name field required." data-val-length-max="20" data-val-length="the field name must string maximum length of 20." data-val="true"> <span class="field-validation-valid" data-valmsg-replace="true" data-valmsg-for="name"></span> -- note automatically added span <span class="indicator required" style="width: 11px;"></span>
i intending have css show image i.e.
span.required { background-image: url("required.png"); }
is possible or need create own helper method implement type of functionality?
yes, it's possible, in general wouldn't recommend it, because templates there customize type rendering, , should able create templates without worrying if overrides template.
i instead create custom labelfor helper, such 1 described here:
or here:
a third option not in mvc, rather add javascript add indicator based on standard mvc validation data attributes (if you're using unobtrusive validation). see answer here:
Comments
Post a Comment