سؤال

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