5
jQuery ($ .post)를 사용하여 HTML 양식을 제출하고 싶지만 MVC 2의 클라이언트 측 유효성 검사 기능을 사용하고 싶습니다. 현재 " OnSubmit "폼 태그의 이벤트,하지만 난 '이상적으로 내가 클라이언트 측 유효성 검사가 jQuery.validation와 함께 일하고있다, 난 그냥 수 있습니다MVC 2 jQuery 유효성 검사 및 아약스 양식
if (formIsValid) {
$.post('<%=Url.Action("{some action}")%>'...
}
를 수행 할 수 있으려면, 검증에 훅 수 없습니다 데이터를 게시하기 전에 유효성 검사가 성공했는지 여부를 테스트하지 마십시오.
앤드류
최종 솔루션
<%
Html.EnableClientValidation();
using (Html.BeginForm("Register", "Account", FormMethod.Post, new { id = "registrationForm" })) {
%>
...
<button type="submit" onclick="return submitRegistration();">Register</button>
<%
}
%>
<script type="text/javascript">
function submitRegistration() {
if ($("#registrationForm").valid()) {
$.post('<%=Url.Action("{some action}")'...
}
// this is required to prevent the form from submitting
return false;
}
</script>