MVC3 html.TextBox
- by BigTommy79
I have login view that takes a LoginPageViewModel:
public class LoginPageViewModel : PageViewModel
{
public string ReturnUrl { get; set; }
public bool PreviousLoginFailed { get; set; }
public LoginFormViewModel EditForm { get; set; }
}
which is rendered in the view. When a user tries to log in I only want to post the LoginFormViewModel (Model.EditForm) to the controller:
public ActionResult Login(LoginFormViewModel loginDetails)
{
//do stuff
}
Using Html.TextBox I can specify the name of the form field manually 'loginDetails.UserName' and post back to the controller and everything works.
@model Web.Controllers.User.ViewModels.LoginPageViewModel
@using (Html.BeginForm()){
@Html.Hidden("loginDetails.ReturnUrl", Model.ReturnUrl)
@Html.LabelFor(x => x.EditForm.UserName, "User Name:")
@Html.TextBox("loginDetails.UserName", Model.EditForm.UserName)
@Html.ValidationMessageFor(x => x.EditForm.UserName)
.....
But what I want to do is to use the staticaly typed helper, something like:
@Html.TextBoxFor(x => x.EditForm.UserName)
But I'm unable to get this to work.
Are you only able to post back the same model when useing the strongly typed helpers? Is there something I'm missing on this? Intellisense doesn't seem to give any clues such as a form field string.