Typically I’m ok with the auto-generated form element names when using the HTML helper like this:
@Html.TextBoxFor(m => m.Property)
Unfortunately, I have a requirement to create an input with a specific name attribute.
I realize I can just build the input using normal HTML and use a model binder or a BindAttribute to retrieve its submitted value. However, I wanted to see if there was a way for me to attribute a property instead to specify both the generated input name and enable the binding.
Is this possible? If so, how can it be done?
Description
One way to set the name of the
inputelement is to use a overload ofTextBoxFor.But this would result in problems with the default model binder. You can create your own ModelBinder to solve this issue.
Sample