0

As I need to check only the items which has value true from controller on jQuery success function.

<script type="text/javascript">

    $("#Pid").change(function () 
         {
            $.ajax({
            url: '@Url.Action("getcheckedchannel","Channels")',
            type: 'POST',
            data: { pid: $(this).val() },
            success: function (data) {
                    for (var i = 0; i < data.length; i++) 
                    {
                       //if (data[i].IsChecked == "1") {
                       var status = data[i].IsChecked ? true : false;
                       $(".IsCheck").attr("checked", status);
                      //}
                     }
            }
      });
    });
</script>
BenMorel
  • 34,448
  • 50
  • 182
  • 322

1 Answers1

0

You can just write this

data[i].IsChecked ? $(".IsCheck").prop("checked", true) : '';

Also consider using .prop instead of .attr to set the checked property

Sushanth --
  • 55,259
  • 9
  • 66
  • 105