Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data-attributes with html editor for mvc

Tags:

asp.net-mvc

Data Attributes for editor for not working.

@Html.EditorFor(model => model.SireTag, new { data_typeahead = "dsfsdfsd" })

When i open my chrome browser i cant see any data-attribute for my text box. I tried goggling and have not found any thing useful.

like image 825
Shanker Paudel Avatar asked Aug 11 '13 22:08

Shanker Paudel


1 Answers

Actually you can use EditorFor and send additional HTML attributes. Use this overload and set the additionalViewData parameters. It expects an object with a htmlAttributes property:

@Html.EditorFor(
    model => model.SireTag,
    new { 
        htmlAttributes = new { data_typeahead = "dsfsdfsd" }
    }
)

This will generate something like:

<input id="SireTag" name="SireTag" ... data-typeahead="dsfsdfsd">
like image 50
Marcos Dimitrio Avatar answered Oct 02 '22 16:10

Marcos Dimitrio