css - MVC data-val-required on element besides input (Html.EditorFor) -
in mvc, when create model property "required" , in html markup create editorfor (input box) property auto-magically adds "data-val-required" css property , can style input box please.
assuming have heading before input box, how detect if editor associated , next required field, can style heading (make red or add asterisk in front of it) instead of input?
<td>heading want style</td> <td>@html.editorfor(model => model.requiredfield)</td>
you can achieve follows:
in model set displayname
attribute property follows:
public class modelname { [required] [displayname("label text")] public string propertyname { get; set; } }
then in view can add class editor label follows:
<td>@html.labelfor(model => model.propertyname , new { @class= "classname" })</td> <td>@html.editorfor(model => model.propertyname )</td>
the above label render follows:
<label for="propertyname " class="classname">label text</label>
thus can style editors label per need.
Comments
Post a Comment