这个代码是设计的登录页面,当我点击登录按钮,并希望显示我的主页.然后登录按钮不工作


[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">
 } 

你的视图应该是这样的

最新更新