2012-02-08 4 views
1

MVC3을 사용 중이고 모델 유효성 검사에 필수 속성을 추가했습니다. 그런 다음 jquery 대화 상자 (아약스 대화 상자 아님)가있는 페이지를 만들었습니다. 이 경우 유효성 검사가 작동하지 않습니다. 하지만 대화 상자에서 html을 페이지에 붙여도 제대로 작동합니다.jquery 대화 상자에서 모델 유효성 검사가 작동하지 않습니다.

신체가 문제를 해결하는 방법을 알고 있습니까? 당신은 당신의 대화의 내부 양식 태그를 이동해야

$(document).ready(function() { 
    $("#registerDialog").dialog({ autoOpen: false, show: "blind", hide: "explode", modal: true, resizable: false, height: 570, width: 390 }); 

    $(".headerButton").button(); 
    $(".accountBtn").button(); 
    $('ul').roundabout({ autoplay: 'false', autoplayDuration: 3000 }); 

    $("#registerBtn").click(function() { 
    $("#registerDialog").dialog("open"); return false; }); 
    $("#closeRegisterDialog").click(function() { $("#registerDialog").dialog("close"); 
    }); 

    $("#registerBtnSbmt").click(function() { 
    $("#registerForm").submit(); return false; }); 
    }) 



@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { id = "registerForm" })) 
{  

    <div id="registerDialog" title="Регистрация"> 
     @Html.LabelFor(x => x.FirstName) 
     <br/> 
     @Html.TextBoxFor(x => x.FirstName, new { @class = "registerUser" }) 
     <br/> 
     @Html.ValidationMessageFor(x => x.FirstName)   
     <br/> 
     @Html.LabelFor(x => x.LastName)   
     <br/> 
     @Html.TextBoxFor(x => x.LastName, new { @class = "registerUser" })    
     <br/> 
     @Html.ValidationMessageFor(x => x.LastName)   
     <br/> 
     @Html.LabelFor(x => x.Email)   
     <br/> 
     @Html.TextBoxFor(x => x.Email, new { @class = "registerUser" })   
     <br/> 
     @Html.ValidationMessageFor(x => x.Email)   
     <br/> 
     @Html.LabelFor(x => x.Password)   
     <br/> 
     @Html.TextBoxFor(x => x.Password, new { @class = "registerUser" })   
     <br/> 
     @Html.ValidationMessageFor(x => x.Password)   
     <br/> 
     @Html.LabelFor(x => x.ConfirmPassword)   
     <br/> 
     @Html.TextBoxFor(x => x.ConfirmPassword, new { @class = "registerUser" })    
     <br/> 
     @Html.ValidationMessageFor(x => x.ConfirmPassword)         
     <br/> 
     @Html.CheckBoxFor(x => x.RememberYou) запомнить Вас?       
     <br/> 
     <br/> 
     @Html.ActionLink("Сохранить", "LogIn", "Account", null, new { @class = "accountBtn", style = "font-size: 0.8em;", id = "registerBtnSbmt" }) 
     <a href="#" class="accountBtn" id="closeRegisterDialog" style = "font-size: 0.8em;">Закрыть</a> 
    </div> 
} 
+0

당신이 대화 –

+0

$ (문서)를 생성하는 데 사용하는 코드를 게시 할 수 있습니다 .ready (함수() { $ ("# registerDialog") 대화 상자 ({ 에 AutoOpen. : 거짓,쇼 : "블라인드", 숨기기 : "폭발", 모달 : 사실, 크기 조정 : 거짓, 높이 : 570, 폭 : 390 }); – Radislav

+0

$ (". headerButton"). button(); $ (". accountBtn"). button(); $ ('ul').원형 교차로 ({autoplay : 'false', autoplayDuration : 3000});$ ("# registerDialog") 대화 상자 ("열기"); $ ("# closeRegisterDialog"). (function() { $ ("# registerDialog") 대화 상자를 클릭하십시오. $ ("# registerBtnSbmt")을 클릭하십시오. (function() { $ ("# registerForm") submit(); false를 반환; }}); }}); – Radislav

답변

2

:

여기 내 자바 스크립트입니다. 대화 상자를 만들고 열 때 양식에서 div가 이동한다는 것을 알 수 있습니다. 당신이 원하는 것 :이 페이지에서이 page

의 하단에 발생하는 이유에 대한 설명이

<div id="registerDialog" title="Регистрация"> 
    @using (Html.BeginForm("Register", "Account", FormMethod.Post, new { id = "registerForm" })) 
    {  

     @Html.LabelFor(x => x.FirstName) 
     <br/> 
     @Html.TextBoxFor(x => x.FirstName, new { @class = "registerUser" }) 
     <br/> 
     @Html.ValidationMessageFor(x => x.FirstName)   
     <br/> 
     @Html.LabelFor(x => x.LastName)   
     <br/> 
     @Html.TextBoxFor(x => x.LastName, new { @class = "registerUser" })    
     <br/> 
     @Html.ValidationMessageFor(x => x.LastName)   
     <br/> 
     @Html.LabelFor(x => x.Email)   
     <br/> 
     @Html.TextBoxFor(x => x.Email, new { @class = "registerUser" })   
     <br/> 
     @Html.ValidationMessageFor(x => x.Email)   
     <br/> 
     @Html.LabelFor(x => x.Password)   
     <br/> 
     @Html.TextBoxFor(x => x.Password, new { @class = "registerUser" })   
     <br/> 
     @Html.ValidationMessageFor(x => x.Password)   
     <br/> 
     @Html.LabelFor(x => x.ConfirmPassword)   
     <br/> 
     @Html.TextBoxFor(x => x.ConfirmPassword, new { @class = "registerUser" })    
     <br/> 
     @Html.ValidationMessageFor(x => x.ConfirmPassword)         
     <br/> 
     @Html.CheckBoxFor(x => x.RememberYou) запомнить Вас?       
     <br/> 
     <br/> 
     @Html.ActionLink("Сохранить", "LogIn", "Account", null, new { @class = "accountBtn", style = "font-size: 0.8em;", id = "registerBtnSbmt" }) 
     <a href="#" class="accountBtn" id="closeRegisterDialog" style = "font-size: 0.8em;">Закрыть</a> 
    } 
</div> 

: 대화 상자의 요구 사항

하나는 표시이다 가장 큰 요소는 입니다. 에서 일관되게이를 수행 할 수있는 유일한 방법은 대화 상자를 본문의 마지막 요소로 사용하는 것입니다.이 방법은 Z- 색인에 대한 DOM 순서를 준수하기 때문에 가능합니다.

move the dialog element back somewhere else in the dom in the open event callback. This has the potential to allow other elements to 

move the dialog content element somewhere else in the dom in the close event callback, before the submit. 

이들 중 어느 쪽이 대화에 구축에 적합하다 (위 참조) 대화 상자의 상단에 표시되며, 는로 남아 있습니다 : 두 가지 작업 차선책은 일반적으로 해결 방법을 제안했다. 이 티켓에 대한 첫 번째 의견은 에서 시사하는 바대로 더 잘 문서화해야합니다.

+0

예, 작동합니다. 고마워요. xbrady !!!!!! 나는 그 문제를 풀기 위해 2 시간 이상을 보냈다. 나는 좀 더 세심해야한다. – Radislav

+0

반갑습니다. 답변으로 표시해주세요. – xbrady

+0

나는 어떻게 해야할지 모르겠다 ... – Radislav

1

먼저 답변을 드리지 못해 죄송합니다. 답변을 참조하십시오. 모달 창에서

  1. 은 없습니다이 속성을 [필수]를 사용,
  2. 이 문제를 해결하기 위해 ... 원인은 페이지 필요한 새로 고침, 그래서 작동하고, 제목을 변경하지, 수 메세지 저장 디폴트를 대체하십시오. 참고 : 지식을 해 있음을 인정하는 약의 코드를 풀어 모달 창을 만들 : (내가 아니 이전 버전으로, ASP.NET MVC 5, 그것은 HTML 5 배에 대한 작품의 사용 해요)

enter image description here

결과의

:

enter image description here

관련 문제