Return an array of values from checkboxes to the controller

Asked

Viewed 24 times

1

I have a problem returning values from my checkbox list, the "checkedcatechesis" array does not reach my controller.

Script:

<script>
    $(document).ready(function () {
        $('[key]').change(function () {
            var key = $(this).attr('key');
            $($('[name="checkedcatequese[' + key + ']"]')).val($(this).is(':checked') ? 'true' : 'false');
        });
    });
</script>

Html:

@foreach (var item in ViewBag.catequizandoSessao)
                        {
                            <tr>
                                <td>
                                  @item.Nome
                                    <input type="hidden" name="pessoaid" id="pessoaid" value="@item.PessoaID"/>                                          
                                </td>                                             

                                <td>
                                    <input type="checkbox" key="@i" />
                                    <input type="hidden" id="checkedcatequese[@i]" name="checkedcatequese[@i]" value="false" />
                                </td>                                                                                    
                           </tr>

                            i++;

Controller:

   public ActionResult CriarAvaliacao(Avaliacao avaliacao,string[] pessoaid, string[] checkedcatequese)
        {

          //codigo

        }
  • Still I can’t solve my problem

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.