Skip to content Skip to sidebar Skip to footer

Giving Editorfor An Id Attribute

I have a template for Views along with lots of JQuery that pulls input from a EditorFor. For this reason I'd prefer to keep using my EditorFor rather than use something like

Solution 1:

Html.EditorFor() helper don't have overload that takes html attributes, use Html.TextBoxFor() helper:

@Html.TextBoxFor(modelItem => item.ReleaseDate, new {@id ="datepicker" })

Here is MSDN documentation for Html.EditorFor() and here is for Html.TextBoxFor()

NOTE:

When you write:

@Html.EditorFor(modelItem => item.ReleaseDate)

It is rendered like this:

<inputtype="text" name="ReleaseDate"id="ReleaseDate"/>

so it sets the id and name attribute to Model property,so you just can use that id if you want to use Html.EditorFor() helper.

Post a Comment for "Giving Editorfor An Id Attribute"