When I click the login button I never get any values posted to the server. I accept a AuthViewModel but it is always null. I have tried using @html.EditorFor but have not had any luck with it.
User Controller
[HttpGet]
public ActionResult Password()
{
UserModel user = (UserModel)Session[Constants.SessionVars.Authenticate];
//error - need a profile
if (user == null)
return Redirect("/User/Login");
return View(new AuthViewModel());
}
[HttpPost]
public ActionResult Password(AuthViewModel password)
{
UserModel user = (UserModel)Session[Constants.SessionVars.Authenticate];
//error - need a profile
if (user == null)
return Redirect("/User/Login");
if (password == null || string.IsNullOrEmpty(password.Password))
{
ViewBag.Error = Constants.ErrorMessages.UserPassword_PassBlank;
return View(new AuthViewModel());
}
var dataContext = new UserdbDataContext();
int code = dataContext.AuthenticateAdmin(user.Id, password.GetHashCode());
//check if password matches
if (code != 1)
{
ViewBag.Error = Constants.ErrorMessages.UserPassword_WrongPass;
return View(new AuthViewModel());
}
//success
Session[Constants.SessionVars.User] = user;
Session.Remove(Constants.SessionVars.Authenticate);
return Redirect("/");
}
User Model
public class AuthViewModel
{
public string Password { get; set; }
}
View
@model MvcApplication1.Models.AuthViewModel
@{
ViewBag.Title = "Password";
}
<h2>Password</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div>@Html.TextBoxFor(m => m.Password,new{placeholder="Password",type="password",autofocus=""})</div>
<div><button id="btnLogin" type="submit">Login</button></div>
<div class="error">@ViewBag.Error</div>
}