put the values of the selected fields to null

0

I am in a project in mvc I have the following.

<script>
$(document).ready(function () {
    $("#selecctall").change(function () {
        $(".checkbox1").prop('checked', $(this).prop("checked"));
    });
});
</script>

<table style=" font-size:20px" align="center" class="table-striped, text-center, table-condensed" cellpadding="20">
    <thead>
        <tr class="text-center" style="color:#e98300;font-family:'Trebuchet MS'">
            <th class="text-center" ; bgcolor="black"><input type="checkbox" name="chkAll" value="All" id="selecctall" /></th>
        </tr>

    </thead>
foreach(filtro de la busqueda)
{
    <tbody>
       <tr style="color:white ;font-family:'Trebuchet MS'">
           <td class="text-center"><input type="checkbox" name="sid" class="checkbox1" /></td>
       </tr>
}
<input name="posponer" class="btn btn-primary btn-lg" type="submit" value="posponer" style=" color:white" title="Operar" />

At the end of the table I have a button, and I need you to take all the checkbox that are marked and go to the controller to be able to operate with them.

    
asked by Zarios 23.06.2016 в 12:00
source

1 answer

1

You could make use of jquery to take the marked check and send the list to the action using $.ajax . What I do not see is where you define the value indicating the value you will send to the action.

If you define

foreach(var item in <filtro>)
{
    <tbody>
       <tr style="color:white ;font-family:'Trebuchet MS'">
           <td class="text-center"><input type="checkbox" name="sid" class="checkbox1" value="@item.Id" /></td>
       </tr>
}

So you use the @item.Id to assign a value, then you would take the list and send it to the action

<script>

    $(function(){

        $('form').submit(function(){
            e.preventDefault();

            var params = {
               selection = []
            };

            $(".checkbox1:checked").foreach(function(){
                params.selection.push($(this).val());
            });

            $.ajax({
                type: 'POST',
                url: '@Url.Action("NombreCtrl", "NombreAction")',
                data: params,
                success: function (data) {
                    //aqui codigo
                }
            });

        });
    })

</script>

The action in the controler would be

public class xxController : Controller
{
    public ActionResult xxAction(List<string> selection)
    {
        //codigo
    }
}

The idea is that the value of the parameter matches that of the params you define in javascript

    
answered by 23.06.2016 в 16:52