2014-04-25 4 views
1

저는 MVC를 처음 접했고이 문제에 다소 혼란 스럽습니다.ReCaptcha MVC 면도기 유효성 검사 메시지가 트리거되지 않음

지난 밤에 Umbraco MVC 4 응용 프로그램 (6.1.6)에서 ReCaptcha를 구현했습니다. ReCaptcha가 작동하면 컨트롤러가 올바른 captcha 유효 상태를 얻고 모두 양호합니다. 문제는 captcha가 올바르지 않은 경우입니다. ModelState.AddModelError (string, string)을 설정하고 모델을 반환하여 captcha가 잘못된 것으로 입력되었지만 뷰가 Html.ValidateMessage ("captcha-error")를 사용하여 ModelState에서 업데이트 된 실제 오류 메시지를 표시합니다.

어떤 도움이나 조언을 주시면 감사하겠습니다

컨트롤러 :

[HttpPost] 
[RecaptchaControlMvc.CaptchaValidator] 
public ActionResult SubmitContactFormAction(Models.ContactFormModel model, bool captchaValid, string captchaErrorMessage) 
{ 
    if (!captchaValid) 
    { 
     ModelState.AddModelError("captcha-error", captchaErrorMessage); 
     return View(model); 
    } 
    else 
    { 
     // Test ModelState and do stuff 
    } 
} 

보기 :

@model WebStaging.Models.ContactFormModel 
@using Recaptcha 
@using (Ajax.BeginForm("SubmitContactFormAction", "ContactForm", null, new AjaxOptions { HttpMethod = "POST" }, new { @id = "frmContactForm" })) 
{ 
    @Html.ValidationSummary(true) 
    <div> 
    Fields marked with * are required<br/><br /> 
    <div class="clear pad-5"> 
     <div class="label-column"> 
     @Html.LabelFor(model => model.Name) * 
     </div> 
     <div class="input-column"> 
     @Html.TextBoxFor(model => model.Name, new { @class = "input-242" })<br /> 
     @Html.ValidationMessageFor(model => model.Name) 
     </div> 
    </div> 
    <div class="clear pad-5"> 
     <div class="label-column"> 
     @Html.LabelFor(model => model.Email) * 
     </div> 
     <div class="input-column"> 
     @Html.TextBoxFor(model => model.Email, new { @class = "input-242" }) 
     </div> 
    </div> 
    <div class="clear pad-5"> 
     <div class="label-column"> 
     @Html.LabelFor(model => model.Phone) 
     </div> 
     <div class="input-column"> 
     @Html.TextBoxFor(model => model.Phone, new { @class = "input-242" }) 
     </div> 
    </div> 
    <div class="clear pad-5"> 
     <div class="label-column"> 
     @Html.LabelFor(model => model.Subject) * 
     </div> 
     <div class="input-column"> 
     @Html.TextBoxFor(model => model.Subject, new { @class = "input-242" }) 
     </div> 
    </div> 
    <div class="clear pad-5"> 
     <div class="label-column"> 
     @Html.LabelFor(model => model.Message) * 
     </div> 
     <div class="input-column"> 
     @Html.TextAreaFor(model => model.Message, new { @class = "input-textarea" }) 
     </div> 
    </div> 
    <br /> 
    <div id="captcha-panel" class="clear" style="text-align: right; float: right; padding-top: 5px;"> 
     @Html.Raw(Html.GenerateCaptcha("captcha", "white"))  
    </div> 
    <p> 
    <div id="captcha-result" class="clear"> 
     @Html.ValidationMessage("captcha-error") 
    </div> 
    <div class="clear pad-5" style="float: right; text-align: center;"> 
     <button type="submit">Send</button><br /> 
     <div id="submit-status" style="color: Green;"></div> 
    </div> 
</div> 
+0

그래서 ajax에서 일반 게시 된 양식 (Html.BeginUmbracoForm())으로 양식이 변경되었으며 예상대로 작동했습니다. 그래서 거기에 내 아약스/JSON 올바른 일을하지 않는 뭔가가있다. –

답변

2

내가 reCAPTCHA를 간단한 웹 컨트롤하지 않기 때문에 문제가 발생합니다 생각합니다. 나는 새로운 클래스 또는 스타일 속성으로 "captcha-result"div를 변경하는 문제를 쉽게 해결할 수 있다고 생각합니다.

jQuery를 사용하는 경우 jQuery Validate plugin을 확인할 수 있습니다.

관련 문제