Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Checkbox not bind in model binding,

the hidden input in bind correctly but only checkbox not work

that is my class:
C#
public class SelectedIDsViewModel
    {
        public bool IsChecked { get; set; }

        public int ID { get; set; }

    }


and that is checkbox:
C#
<form asp-action="DeleteAll" asp-controller="Admin" method="post">

@for (int i = 0; i < Model.ArticleDetails.Count(); i++)
{

      <input name="@("ddd["+ i + "].IsChecked")" type="checkbox" />
      <input name="@("ddd["+ i + "].ID")" value="@Model.ArticleDetails[i].ArticleID" type="hidden" />
}

</form> 


and that is my method action:

[HttpPost]
public IActionResult DeleteAll(List<SelectedIDsViewModel> ddd)
{

     return View();
}


What I have tried:

I tried all my best but i cannot solve it i need help ...
Posted
Updated 18-Jul-17 17:50pm

1 solution

You should use checked [^] attribute to check/uncheck the state of a checkbox
syntax should be something like this, please verify
<input checked="@(" ddd["+ i + "].IsChecked" ? 'checked':'' )" type="checkbox" />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900