Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

using MVC and Ajax on checkbox from list Change select other checkboxes

$
0
0

hi

I have list of checkboxes. When an checkbox is selected it is sent Get to the controller and the controller should return list of dependent Ids that need to be checked too. For example: if checkbox with ID 1 is checked, the controler should return list of dependent ids like {5,6,7} and the sheckboxes with ids {5, 6, 7} should be checked. here  is my code:

view:

 @for (var i = 0;  i < Model.DocumentTypes.Count;     ++i)
{<tr><td><div class="custom-control custom-checkbox"><input type="checkbox" id="@Model.DocumentTypes.ElementAt(i).Key" onclick="FindDependentDocumentTypes(@Model.DocumentTypes.ElementAt(i).Key)"><label class="custom-control-label" for="@Model.DocumentTypes.ElementAt(i).Key">@Model.DocumentTypes.ElementAt(i).Value</label></div></td></tr>

}

<script>
    function FindDependentDocumentTypes(itemId) {$.get("/Home/GetDependents?i=" + itemId).done(function (data) {
            if (data.success) {
               // HERE I NEED HELP HOW TO CHECK ALL THE CHECKBOXES WHOSE iDS ARE IN THE LIST

            }
            else {
                alert(data.message);
            }
        });
    }
</script>

Controller

        [HttpGet]
        public ActionResult GetDependents(int i)
        {
            var List1 = GetDependentDocumentTypes(i);
            return View(List1);
        }

Please advice How to select the dependent checkboxes? 


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>