How can I bring the  checkbox   value if ticked  as 1 else 0   to the controller model RRS feed

  • Question

  • User-1355965324 posted

    How can I bring the  checkbox   value if ticked  as 1 else 0   to the controller argument  variable _depotid   when I click submit button. Please can you help

    public class DepotUserLink
    public List<int> DepotsID { get; set; }
    public bool checkboxDepotLink { get; set; }
    public bool checkboxDefaultDepot { get; set; }
    //In Controller
    public IActionResult DepotUserLink(DepotUserLink depotuserlink)
       DepotsID  =  should be stored with selected userdepot Value

                                        @foreach (var _userDepot in ViewBag.UserDepots)
                                                <td style="display:none;"  >
                                                    <input type="checkbox" name="DepotLink" asp-for="checkboxDepotLink" />
                                                    <input type="checkbox" name="DefaultLink" asp-for="checkboxDefaultDepot" />
    <div class="center-block  col-sm-6">
                                            <button type="submit" class="btn btn-primary form-control">Save</button>
     $("#DepotCheck").click(function () {
    $('input[name="DepotLink"]:checkbox').not(this).prop('checked', this.checked);

    Wednesday, December 5, 2018 10:56 AM


  • User1520731567 posted

    Hi polachan,

    For example,if you select DepotCheck, all checkbox named DepotLink will be selected,

    you just modify the controller,like:

            public IActionResult DepotUserLink(DepotUserLink depotuserlink,string[] DepotLink)
                return View();

    string[] DepotLink will get all value of checkbox named DepotLink.

    if you would like to get their Id,you could modify,like:

    <input type="checkbox" name="DepotLink" value="@_userDepot.Id" asp-for="checkboxDepotLink" />

    Like the picture:

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 6, 2018 6:05 AM