In the previous version of ASP. net mvc Verification Code demonstration, http://www.cnblogs.com/insus/p/3622116.html. insus.netalso uses generic handler to generate a verification code image, which has been used by Insus. NET in asp.net development.
In this article, Insus. NET does not use ASHX. There are many methods in MVC development.
You can create a custom Result named CaptchaResult. cs to inherit the ContentResult class.
In the controller, write three actions: ActionResultCaptchaDemo_Ver2(), CaptchaResultGetCapptImage() And JsonResultCaptchaValid(String captchaText ).
The following is the implementation View:
Mark 1: write html markup. There is a file box for users to enter the characters of the Verification Code, there are img displaying the verification code, the verification button, and the display information label.
Mark 2 to reference the jQuery library.
Mark 3. When the view is loaded for the first time, the dynamically generated verification code is displayed.
Mark 4. Click the verification code image to change it instantly.
Mark 5 to verify that the verification code entered by the user is correct.
Mark 6 to pass in the verification code entered by the user.
Mark 7 and return the verification result.
Test Run page to see whether the correct verification code is entered, all get "Not Found ".
The attribute of the original Action is different from the request method used by jQuery. One is POST and the other is HttpPost. The correct method is POST> HttpPost;
Change to consistency to solve the problem. Demonstration: