Hi alya14,
Check the below sample and modify your code accordingly.
Model
public class EmployeeModel
{
public int Id { get; set; }
public string Name { get; set; }
public int IsActive { get; set; }
}
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
List<EmployeeModel> employees = new List<EmployeeModel>();
employees.Add(new EmployeeModel { Id = 1, Name = "John Hammond", IsActive = 0 });
employees.Add(new EmployeeModel { Id = 2, Name = "Mudassar Khan", IsActive = 1 });
employees.Add(new EmployeeModel { Id = 3, Name = "Suzanne Mathews", IsActive = 0 });
return View(employees);
}
}
View
@model IEnumerable<_Check_CheckBox_Model_MVC.Models.EmployeeModel>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<table class="table">
<tr>
<th>@Html.DisplayNameFor(model => model.Name)</th>
<th>@Html.DisplayNameFor(model => model.IsActive)</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.Name)</td>
<td><input name="IsActive" type="checkbox" checked="@(item.IsActive == 1)" /></td>
</tr>
}
</table>
</body>
</html>
Screenshot