asp.net mvc - How to get the selected values from MVC CheckBoxFor jquery? -


i working on mvc app , right stuck on following problem: have checkboxes generated 1 of models, don't know how value(either name of id) of selected ones in javascript. ideas ?

here's code:

@if (model.controls.any())        {             (int x = 0; x < model.controls.count(); x++)            {         <div aria-autocomplete="inline">              @html.checkboxfor(p => p.controls[x].isselected, new { @class = "ccb" })             @html.label(model.controls[x].name)             @html.hiddenfor(p => p.controls[x].id)          </div>            }         } 

working :

$(document).ready(function () {     $('.ccb').change(function (event) {         var matches = [];         $(".ccb:checked").each(function () {             matches.push(this.value);         });         alert(matches);      }); }); 

try:

$(document).ready(function () {     $('.ccb').change(function (event) {         if ($(this).is(':checked'))         {             var theid = $(this).attr('id'); // id of checkbox             var thevalue = $(this).val(); // value field of checkbox         }     }); }); 

see how can checkboxlist selected item value.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -