5
jQuery($ .post)を使用してHTMLフォームを送信したいのですが、MVC 2のクライアント側の検証機能を使用したいと思います。現在、私は " OnSubmitの」formタグのイベントが、私は「理想的な私は、クライアント側の検証がjQuery.validationと協力して、私はちょうどすることができますのでご注意くださいMVC 2 jQueryの検証とajaxのフォーム
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>