udayr
udayr

Reputation: 63

How to add Id and Name attributes to the options for ASP.NET MVC dropdownlist element?

I am using Html.DropdownList() html extension in ASP.NET MVC. It is currently generating the following html.

<select id="MyItems" name="MyItems">
    <option value="1">Swimming</option>
    <option selected="selected" value="2">Cycling</option>
    <option value="3">Running</option>
</select>

I would like to have Id and name attributes for each 'option' element in the the 'select` element.

Any suggestions on how I could achieve it?

Thanks in advance.

Upvotes: 0

Views: 1451

Answers (2)

user1503035
user1503035

Reputation: 11

Its not possible with Html.DropdownList()

you have option that you can generate this drop down using jquery then add this id and name attribute.

This will help you.

Upvotes: 1

Prabu
Prabu

Reputation: 4187

This is not possible out of the box as far as I can see. However, I believe this answer will lead you to the answer you need.

Upvotes: 0

Related Questions