weixin_33692284 2013-03-07 12:48 采纳率: 0%
浏览 23

CaptchaMvc与Ajax

I'm using mvc4 c# and view with a form inside a CaptchaMvc.

I send the form data over ajax :

$.ajax({
            url: $('#registerForm').attr("action"),
            type: 'POST',
            contentType: 'application/json',
            dataType: 'json',
            data: JSON.stringify($('#registerForm').serialize()),
            beforeSend: function () {

            },
            success: function (result) {
                //debugger;


            },
            error: function (event, request, settings) {
                //debugger;

            }
        });

I can see on firebug that "CaptchaInputText" sended to server, but still I get error

[NullReferenceException: Object reference not set to an instance of an object.]
CaptchaMvc.Infrastructure.DefaultCaptchaManager.ValidateCaptcha(ControllerBase controller, IParameterContainer parameterContainer) in g:\CodePlex\Captcha\CaptchaMvc(Mvc 3)\Infrastructure\DefaultCaptchaManager.cs:435

and It occur if I have the line :

[CaptchaMvc.Attributes.CaptchaVerify("Captcha is not valid")] 

on the controller action, If not ,there is no error but the captcha not getting validated. what to do ?

  • 写回答

1条回答 默认 最新

  • weixin_33724059 2013-03-15 17:45
    关注

    Try to change your request like this:

    $.post($('#registerForm').attr("action"), $('#registerForm').serialize(),
            function(data) {
    
            }
        );
    

    I've updated the examples and added an example with ajax request, you can download it here.

    评论

报告相同问题?