0

I generate html textbox in this way:

<%: Html.TextBoxFor(m => m.Category) %>

ASP.NET MVC render html:

<input type="text" value="" name="Category" id="Category">

Is there is a way to set manually name of the textbox not eqaul to property "Category", but something else?

Thanks.

2 Answers 2

3
<%: Html.TextBox("someOtherName") %>
Sign up to request clarification or add additional context in comments.

2 Comments

Why Html.TextBoxFor doesn't offer this overload?
Because Html.TextBoxFor is supposed to generate input fields with proper names according to your view models so that when you submit the form to the server it automatically binds the values. Doing it manually is wrong and might not work. For example if you had complex properties, lists and dictionaries the strongly typed helper will do the job of generating correct names.
0

You have to change the default editor template or add a new template for this. You can refer this blog post from Brad Wilson for some insight.

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.