我有一个登录页面和一个注册页面。两者都顺利验证。当我将成员资格添加到登录控制器时,登录页面停止验证字段,但是根据我的代码,它只是弹出登录失败的消息。以下是我的行动和观点。知道为什么它没有验证知道我在注册视图中有相同的代码及其验证。
动作
[HttpPost]
public ActionResult SignIn(tbl_User user)
{
try
{
if (Membership.ValidateUser(user.UserEmail, user.Password))
{
FormsAuthentication.SetAuthCookie(user.UserEmail, false);
return RedirectToAction("Index", "Home", new { area = "Common" });
}
else
{
TempData["Msg"] = "Login Failed";
return RedirectToAction("Index");
}
}
catch(Exception e)
{
TempData["Msg"] = "Login Failed "+e.Message;
return RedirectToAction("Index");
}
}
查看
@model BOL.tbl_User
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Login</h2>
@if (TempData["Msg"] != null)
{
<div class="alert alert-dismissible alert-info">
<button type="button" class="close" data-dismiss="alert">×</button>
@TempData["Msg"].ToString()
</div>
}
@using (Html.BeginForm("SignIn","Login",FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.UserEmail, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserEmail, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.UserEmail, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
</div>
</div>