I'd like to be able to make a data attribute in c# for an object in my model. When this is displayed. I'd like the html to render the value in a data attribute within the html itself.
In my head, the code looks similar to this.
public class AffectsAttribute:Attribute
{
public string[] Departments { get; set; }
}
[EmailAddress]
[Required(ErrorMessage = "Email is required")]
[Affects(Departments = new string[]{"Coaches"})]
public string Email {get; set;}
Then in the html, after being called with razor it would look something like this
@Html.EditorFor(model => model.Email)
<input class="text-box single-line" data-affects="Coaches" data-val="true" data-val-email="The Email field is not a valid e-mail address." data-val-required="Email is required" id="Email" name="Email" type="email" value="">
I have no clue how to specify that I would like the additional data attribute to be added when the item is rendered on a page. Can anyone help?