1
Vote

Add Overloads to InputExtensions xxxFor Methods With Id Prefix

description

I don't know if this has happened to other people, but it has happened to me: the xxxFor methods in InputExtensions (TextBoxFor, LabelFor, etc) generate HTML content where the id and name attributes come from the property name. There is a problem if we use TextBoxFor, for example, on a view, two times with the same property names, even if they come from different classes.
So, I propose an overload (or the actual substitution of the current methods) for each of these methods that takes a prefix and applies it to the id attribute (not the name one, since this is required for binding to the model), such as:

public static MvcHtmlString TextBoxFor<TModel, TProperty>(
this HtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TProperty>> expression,
String prefix = null
)

This way, we avoid id clashes on the HTML, while preserving binding compatibility.

comments

HongmeiG wrote May 21, 2012 at 10:00 PM

Can you see if we already support this?

rjperes wrote Aug 16, 2012 at 10:05 PM

Any news on this? Any chance this may be implemented?
Thanks!