문제

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