MVC4验证码不爽快?

时间:2016-07-12 20:10:53

标签: asp.net asp.net-mvc-4 captcha

    @using CaptchaMvc.HtmlHelpers

    ------------



<div class="form-group">
                    <div class="col-md-12">
                        <div class="input-group">
                            <div class="input-group-addon"><i class="fa fa-fw fa-at"></i></div>
                            @Html.TextBoxFor(m => m.Email, new { @class = "form-control", @placeholder = "Email Address" })                           
                        </div>

                        <div id="email-error-message">
                            @Html.ValidationMessageFor(m => m.Email, "", new { @class = "text-danger" })
                        </div>                     


                        @Html.Captcha(5)


                        <div id="captcha-validation-message"></div>
                        <br />
                        <button class="btn btn-primary" type="submit">@Model.ButtonText</button>                      
                    </div>
                </div>

C#代码:

       [HttpPost]
        [AjaxOrChild]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Login(LoginViewModel model)
        {
           if(this.IsCaptchaValid("Captcha is not valid"))
            {
                model.IsValidated = true;
                model.Error = "";
            }
           else
            {
                model.IsValidated = false;
                model.Error = "Human validation failed!";                              
                return Json(model, JsonRequestBehavior.AllowGet);
            }
}

如果他们正确进入验证码,一切正常。但如果他们输错了,验证码就不会重新加载。此外,即使我正确输入验证码,它也会一直失败,直到我刷新整个页面。

0 个答案:

没有答案