tags:

views:

24

answers:

2

ASP.Net Html.TextBoxFor (and the other XxxxxFor editor helper methods) default to rendering a field prefix. How do I disable field prefixes so it simply renders the property name as the Name/ID?

Here's an example:

<%= Html.EditorFor(m => chart.Title) %>

is rendered as:

<input id="Chart_Title" name="Chart.Title" type="text" value="">

I would prefer it to be rendered as:

<input id="Title" name="Title" type="text" value="">
+1  A: 

Hey,

The helpers take whatever you give it. So you need to pass in just the "Title" portion of the variable; maybe try assigning title to a variable, and use Html.EditorFor for that Title variable, and that might give you a different response.

The reason it does that is the helpers are setup to reflect from the Model context, so typically you may see Model.Chart.Title, and as such, the helpers create this path in the name so it can post the entire model back to the action method, if it needed to.

HTH.

Brian
+1  A: 

There's a parameter in an overload of EditorFor called htmlFieldName. Specify your name here.

Tim