I have a ViewModel class composed of several nested classes:
public class UserAccountViewModel : UserProfileViewModel
{
public UserAccountEmailViewModel UserAccountEmail { get; set; }
public UserAccountLocationViewModel UserAccountLocation { get; set; }
public UserAccountPasswordViewModel UserAccountPassword { get; set; }
}
The HTML rendered from this (pay attention to model.UserAccountEmail.Email):
<div class="editor-label">
@Html.LabelFor(model => model.UserAccountEmail.Email)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.UserAccountEmail.Email)
@Html.ValidationMessageFor(model => model.UserAccountEmail.Email)
</div>
Is this:
name="UserAccountEmail.Email"
I would prefer the name to simply be Email
Changing ViewData.TemplateInfo.HtmlFieldPrefix didn't help. Overloading the htmlFieldName in @Html.EditorFor isn't going to work because I still want the label and validation message to match the rendered HTML element (no overload for htmlFieldName in these functions).
I'd prefer to not create partials for this.
Edit:
Meh...using partials actually isn't too bad. It actually makes quite a lot of sense.