2012-01-24 22 views
0

我動態繪製選框在我的表列表:如何使AJAX回發的形式複選框

@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { id="itemsList"})) 
{ 
foreach (var lt in Model.MyList) 
      {     
       <li>     
        <label id="label"> 
         <input value="@lt.itemId" type="checkbox" /> 
         @lt.Title</label> 
       </li>       
      } 
} 

jQuery函數:

$(document).ready(function() { 
     $('#itemsList').ajaxForm({ 
      success: Saved, 
      error: HandleError 
     }); 
    }); 
... 

但是我的動作沒有被解僱。我在這裏做錯了什麼?我期待當我檢查複選框使服務器調用。

回答

1

我期待當我檢查複選框使服務器調用。

你不應該指望,除非你寫的處理程序複選框變化

$(document).ready(function() { 
     $('#itemsList').ajaxForm({ 
      success: Saved, 
      error: HandleError 
     }); 

     $(':checkbox').change(function(){ 
      $('#itemsList').submit(); 
     }); 
}); 
0

ajaxForm將攔截提交併通過ajax發送它們。但是,你需要觸發提交Ajax調用在踢

嘗試增加:

$('input[@type="checkbox"]').click(function(){ $('#itemsList').submit(); } 

您可能需要細化的複選框選擇到更具體的東西...