2013-04-23 31 views
1

我正在使用MvcCaptcha。 对于这一点,我用这个参考 http://sameercode.wordpress.com/2013/01/08/mvc-captcha-using-dll/未在MVC4中生成Captha图像

http://captchamvc.codeplex.com/releases/view/103937

enter image description here

我随后的所有步骤,但不获取生成验证码的图像。

请参阅附件图像

我是否需要添加任何配置设置..

应显示为

enter image description here

+0

你能粘贴图像是不显示的网址是什么?使用开发工具并检查该破碎的图像。 – mattytommo 2013-04-23 14:26:34

+0

我是CaptchaMvc项目的开发者。确保你使用了MVC4库,如果问题仍然存在,请创建工作项目[here](http://captchamvc.codeplex.com/workitem/list/basic)。 – 2013-04-29 08:42:49

+0

问题已解决...随着CaptchaMVC.dll,我还需要包含xml文件。我添加了使用Nuget的参考,它的工作原理 – Marcus25 2013-05-09 06:11:47

回答

0

在这个例子中,我将使用一个实现图像为MathCaptcha。在控制器你应该增加:

using CaptchaMvc.Attributes; 
... 
// At the action that process your form you have to add the [CaptchaVerify] atttribute 
[HttpPost] 
[CaptchaVerify("Captcha result is not valid.")] // Captcha is now able for validation 
public ActionResult yourAction(FormCollection collection) 
{ 
     if (!ModelState.IsValid) 
     { 
      ViewBag.Error = "The captcha answer is not correct."; 
      return View("SameViewForm"); 
     } 
     else 
     { 
      ... 
      // Whatever you have to do when Captcha answer is correct. 
      return View(); 
     } 
} 

在视图:

// Add 
@using CaptchaMvc.HtmlHelpers 
... 
@using (Html.BeginForm()) 
{ 
    ... 
    <label style="color: red">@ViewBag.Error</label> 
    @Html.MathCaptcha() 
    <input type="submit" value="Send" /> 
}