1

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="">

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.