[HttpPost]
public ActionResult Login (LoginViewModel model)
{
if (ModelState.IsValid)
{
DataBaseContext db = new DataBaseContext();
var user = db.tblUsers.SingleOrDefault(x => x.UserName == model.UserName && x.Password == model.Password);
if (user != null)
{
return RedirectToAction("Registration", "Home");
}
else
ModelState.AddModelError("", "Invalid userName or Password");
}
return View(model);
}
这是登录页面代码,当我运行此代码并移动注册页面时,这不起作用。
@using (Html.BeginForm("Login", "CotrollerName", FormMethod.Post))
{
<label for="UserName">User Name:</label>
@Html.TextBoxFor(model => model.UserName)
<label for="Password">User Name:</label>
@Html.TextBoxFor(model => model.Password)
<input type="submit" value="Submit">
}
你的视图应该是这样的