質問

I want like to create a input box with a data-popup attribute like this:

<input type="text" name="title" data-popup="test">

I tried to use

@Html.EditorFor(model => model.Name , new { data_popup = "Hashtag" })

but the data-popup attribute is not rendered. Is it possbile to add a attribute like data-popup for an editorfor?

役に立ちましたか?

解決

I believe if you use TextBoxFor instead in the same way, you will get the results you desire.

The reason being is EditorFor doesn't have a parameter for htmlAttributes, the parameter you are passing is the additionalViewData parameter, and therefore will not be rendered as html attributes..

他のヒント

Yes, but then you have to write your own editor markup (http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-3-default-templates.html). Otherwise, it is usually much easier to just use TextBoxFor instead.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top