2013-04-23 41 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" /> 
}