JS:
rules: { Email: { required: true, email: true }, Password: { required: true, remote: { url: "/Users/Login", type: "Post", data: { Email: function () { return $("#Email").val(); }, Password:function(){return $("#Password").val();} } } }, remember: { required: false } },
cshtml:
<form class="login-form" action="/Users/Login" method="post"> <h3 class="form-title">Sign In</h3> <div class="alert alert-danger display-hide"> <button class="close" data-close="alert"></button> <span>Email or Password is wrong!</span> </div> <div class="form-group"> <label class="control-label visible-ie8 visible-ie9">Email</label> <input class="form-control form-control-solid placeholder-no-fix" type="text" autocomplete="off" placeholder="Email" name="Email" id="Email"> </div> <div class="form-group"> <label class="control-label visible-ie8 visible-ie9">Password</label> <input class="form-control form-control-solid placeholder-no-fix" type="password" autocomplete="off" placeholder="Password" name="Password" id="Password"/> </div> <div class="form-actions"> <button type="submit" class="btn btn-success uppercase">Login</button> <label class="rememberme check"> <input type="checkbox" name="remember" value="1" />Remember </label> <a href="javascript:;" id="forget-password" class="forget-password">Forgot Password?</a> </div> <div class="create-account"> <p> <a href="javascript:;" id="register-btn" class="uppercase">Register an account</a> </p> </div> </form>
Controller:
[HttpPost] public ActionResult Login(string Email,string Password) { string Msg = ""; try { string outmsg = ""; WeUser user = wbll.ULogin(Email, Password, out outmsg); switch (outmsg) { case "-1": //没有此帐户或帐户错误 Msg = "false"; break; case "error": //密码错误 Msg = "false"; break; case "succeed": Msg = "true"; return RedirectToAction("Index", "UsersCenter"); default: break; } } catch { Msg = "false"; } return Content(Msg); }
当密码输入框失去焦点时出现如下提示:
当点击“LOGIN"提交登录时会出现如下提示:
学习交流群:364976091