2012-01-24 78 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(); } 

您可能需要细化的复选框选择到更具体的东西...