Hi LoganTRK,
Check this example. Now please take its reference and correct your code.
Model
public class CustomerModel
{
public int Id { get; set; }
public string Name { get; set; }
public bool IsCheck { get; set; }
}
Home Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
List<CustomerModel> customers = Customers();
return View(customers);
}
private List<CustomerModel> Customers()
{
List<CustomerModel> customerList = new List<CustomerModel>();
customerList.Add(new CustomerModel() { Id = 1, Name = "John Hammond", IsCheck = false });
customerList.Add(new CustomerModel() { Id = 2, Name = "Mudassar Khan", IsCheck = false });
customerList.Add(new CustomerModel() { Id = 3, Name = "Suzanne Mathews", IsCheck = false });
customerList.Add(new CustomerModel() { Id = 4, Name = "Robert Schidner", IsCheck = false });
return customerList;
}
[HttpPost]
public ActionResult ViewTraza(string[] selected)
{
List<CustomerModel> customerModel = Customers();
foreach (CustomerModel model in customerModel)
{
if (selected.Contains(model.Id.ToString()))
{
model.IsCheck = true;
}
}
// TempData to send the model to another controller.
TempData["Customers"] = customerModel;
return RedirectToAction("Index", "Detail");
}
}
Home View
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<_987174_CheckBox_Value_To_Another_View.Models.CustomerModel>>" %>
<%@ Import Namespace="_CheckBox_Value_To_Another_View.Models" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Index</title>
</head>
<body>
<h4>
Home Controller</h4>
<hr />
<% Html.BeginForm("ViewTraza", "Home", FormMethod.Post);
{%>
<table>
<tr>
<th>Id</th>
<th>Name</th>
<th>Action</th>
</tr>
<% foreach (CustomerModel item in Model)
{ %>
<tr>
<td><%: item.Id %></td>
<td><%: item.Name %></td>
<td><input type="checkbox" name="selected" value="<%: item.Id %>" /></td>
</tr>
<% } %>
</table>
<br />
<input type="submit" value="Submit" />
<% }%>
</body>
</html>
Detail Controller
public class DetailController : Controller
{
// GET: /Detail/
public ActionResult Index()
{
List<CustomerModel> customers = (List<CustomerModel>)TempData["Customers"];
return View(customers);
}
}
Detail View
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<_987174_CheckBox_Value_To_Another_View.Models.CustomerModel>>" %>
<%@ Import Namespace="_CheckBox_Value_To_Another_View.Models" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Index</title>
</head>
<body>
<h4>
Detail Controller</h4>
<hr />
<table>
<tr><th>Id</th>
<th>Name</th>
<th>Action</th>
</tr>
<% foreach (CustomerModel item in Model)
{ %>
<tr>
<td><%: item.Id %></td>
<td><%: item.Name %></td>
<td><%=Html.CheckBox("chk", item.IsCheck) %></td>
</tr>
<% } %>
</table>
</body>
</html>
Screenshot
