2011-12-02 54 views
1

我有这样调用操作从的onclick方法

<td><%= Html.CheckBox("seleccionado", false, new { onclick = "SeleccionarItems();" })%></td> 

一个CheckBox现在,我想从我的控制器调用特定的动作,并通过复选框的价值如何能做到这一点..

function SeleccionarItems() { 
      -- call method to controller and pass value 
     } 

回答

5

我会使用jQuery张贴到控制器:

http://api.jquery.com/jQuery.ajax/

$.ajax({ 
    type: 'POST', 
    url: controllerName + '/ActionName', 
    data: { 'checkValue': $('#seleccionado').val() }, 
    dataType: 'json', 
    success: function (jsonData) { 
     //This function gets called after posting to the server 
    }, 
    error: function() { 
     alert('Error!'); 
    } 
}); 

这里是一个解释整个过程的教程:Link