Click here to Skip to main content
15,843,149 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:
public class SelectedIDsViewModel
        public bool IsChecked { get; set; }

        public int ID { get; set; }


and that is checkbox:
<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" />


and that is my method action:

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 ...
Updated 18-Jul-17 18: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