public ActionResult Logon()
{
return View();
}
public ActionResult CheckUserLogin(string UserName, string UserPsw)
{
#region 校验是否登录成功
//校验用户名密码是否匹配
//可以通过request或者括号传参的形式,接到前台的值;
string userName =UserName;// Request["UserName"];
string userPwd = UserPsw;// Request["UserPsw"];
var currentUser = userService.LoadEntitys(u => (u.UserName == null ? "" : u.UserName).ToLower() == userName.ToLower() || (u.UCode == null ? "" : u.UCode).ToLower() == userName.ToLower()).FirstOrDefault();
if (currentUser == null)
{
return Content("用户名不存在!");
}
if (currentUser.UserPsw.Trim() != userPwd.Trim())
{
return Content("密码错误!");
}
//将用户放到session
Session["loginusername"] = currentUser.UserName;
Session["LoginUser"] = currentUser;
// return r("<script>alert('null');</script>");
return Content("ok");
#endregion
}
前端需根据文本的name的名字 写成括号传成的参数;
@using (Ajax.BeginForm("CheckUserLogin", "Login", new { }, new AjaxOptions() { HttpMethod = "Post", OnFailure = "AlertFailed", OnSuccess = "AddSuccess" }, new { id = "form1" }))
{
<div class="login">
<div class="input">
<input type="text" name="UserName" id="UserName" value="" class="LoginUserTxt" chk="null" tit="用户名">
<span class="TxtName">用户名/用户编号</span>
<input type="password" name="UserPsw" id="UserPsw" class="LoginUserTxt" value="" chk="null" tit="密码" style="margin-left:23px;"/>
<span class="TxtName psw">密码</span>
<input type="button" name="button" id="button" class="LoginPwdBtn" />
</div>
</div>
}