2011-05-05 99 views
0

我的問題是我使用MVC3的不顯眼的客戶端驗證的功能,但我需要鉤入它並添加一個函數,在成功驗證但在表單發佈之前觸發。使用MVC的jQuery驗證問題3

我希望有一些預構建的幫手或簡單的方法來鉤入驗證程序。

這裏有一個代碼片段:

@using (Html.BeginForm("MyAction","MyController")) { 
     @Html.ValidationSummary(true) 
     <fieldset> <legend><legend> 
     <label for="FirstName">First Name</label> 
     @Html.TextBoxFor(model => model.FirstName) 
     @Html.ValidationMessageFor(model => model.FirstName) 

回答

0

我最終需要掛鉤到驗證過程來執行我自己的自定義驗證,也做一些div崩潰。這是jQuery的一個片段,它完成了我所需要的:

//Hijack the submit event to do custom validation and collapse the div 
    $('#theFormName').submit(function() { 
     var customErrorHandling = false; 

     //do some custom validation 

     if (customerErrorHandling == false) { 

      //Now do the jQuery validation 
      if ($('#theFormName').valid()) { 

       //do some div collapsing 

       $('#theFormName').unbind('submit'); 
       $('#theFormName').submit(); 
      } 
     } 
     return false; 
    });