I want to add a custom data attribute to each option in my selectlist, which I could achieve with jQuery.data() or .attr().
However, I am setting up my selectlists with the following html helper:
@Html.EditorFor(x => x.MySelect, MVC.Shared.Views.EditorTemplates.KeyValuePairSelectList, new { SelectListOptions = Model.MySelectList})
Is there a way to do it in the new{} method of the EditorFor?
I will try using any one of the two ways described below,
1. Using custom editor template
Suppose we want to display
MyModelarray as a dropdownlist and the propertiesSomeProperty1andSomeProperty2to be displayed as data attributes in the <option> element.2. Using templated razor delegates