-offset-2 col-md-10">
<input type="submit" value="Log in" class="btn btn-default" />
</div>
</div>
}
</section>
</div>
<div class="col-md-4">
@*<section id="socialLoginForm">
@Html.Partial("_ExternalLoginsListPartial", new ExternalLoginListViewModel {ReturnUrl = ViewBag.ReturnUrl})
</section>*@
</div>
</div>
@section Scripts{
<script type="text/java script">
$(function () {
$("#valiCode").bind("click", function () {
this.src = "CreateVerifyCode?style=type1&time=" + (new Date()).getTime();
});
});
</script>
}
后端代码使用 [HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid) return View(model);
if (string.Compare(Session["validateCode"].ToString(), model.VerifyCode,
StringComparison.OrdinalIgnoreCase) != 0)
ModelState.AddModelError("VerifyCode", "验证码验证不通过.");
else
return RedirectToAction("Index", "Home");
return View();
}
运行效果
|