I have a model element, for example:
[Required]
[Display(Name = "First name")]
[StringLength(50)]
public string FirstName { get; set; }
and I use the editor to pump it to the page like this:
@Html.EditorFor(x => x.FirstName )
I have many of these elements on the page and would like to add a CSS class to the input field called "Required" based on whether the model has the [Required] attribute.
Adding ...
@Html.EditorFor(x => x.FirstName, new { @class = "Required" }) )
... seems a little tame. Can I do it dynamically?
Thank you in advance
source
share