Controlling the name of input fields using HtmlHelper
I'm building a form in ASP.NET MVC3 + Razor that posts to a PHP page which uses a different convention for naming the input fields. I need to make MVC's field names conform to the names that the PHP page is using. Instead of the input name being Customer.EmailAddress
, I need the field name to be customer[开发者_JAVA技巧email_address]
.
I've been using the Html.TextBoxFor
, Html.LabelFor
and Html.ValidationMessageFor
methods on other pages, and I'd like to get the same functionality of generating validation from the attributes on my viewmodel. How do I customize the input name that Html.TextBoxFor is generating, and still get the validation behavior?
I've seen the Bind attribute, but that only seems to affect data being received by the server, not being rendered by the server.
So it was easier than I thought. For anyone trying to solve this problem, here's what I did
@Html.EditorFor(model => model.RegistrationDetails.Email, null, "customer[email_address]")
精彩评论