vendredi 1 mai 2015

how to send multiple selected checkbox checked value from nested loop with ajax?

I want to send multiple selected checkbox value with ajax to my controller and filter data based on selected checked value.

This is my model:

 public class sample
        {
            public int Id { get; set; }

            public string parent { get; set; }
            public virtual ICollection<childsample> childsamples { get; set; }
        }

        public class childsample
        {
            public int childid { get; set; }
            public string child { get; set; }
        }

My view(.cshhtml):

@foreach (var sample in Model.sample)
     {
                       <label class="Parentlabel">
                            <input type="checkbox" name="parentHeader" class="ParentHeader Right5" />
                            @sample.parent 
                        </label>

          <div class="bgContainer">
                            @foreach (var child in @sample.childsamples)
                            {
                 <label class="childLabel">
                                        <input class="ChildHeader Right5" type="checkbox" 
                                               name="childHeader" value="@child.child" />@child.child
                                    </label>
                            }
                    </div>
      } 

can anybody tell me how do i send this multiple checked checkbox value to my controller with ajax and filter data based on checked checkbox value?




Aucun commentaire:

Enregistrer un commentaire