MVC3 html.TextBox
Posted
by
BigTommy79
on Stack Overflow
See other posts from Stack Overflow
or by BigTommy79
Published on 2011-04-27T16:45:57Z
Indexed on
2012/11/11
23:00 UTC
Read the original article
Hit count: 164
asp.net-mvc-3
|html-helper
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.
© Stack Overflow or respective owner