Well, I dont think this will automatically work, so you will have to build out the grid your self and then parse the results to re-persist them. Its not actually that hard. I have written a sample app for you below...
Controller:
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
LinkDeviceAndProject Model = new LinkDeviceAndProject();
Model.Devices = GetDevices();
Model.Projects = GetProjects();
return View(Model);
}
[HttpPost]
public ActionResult Index(FormCollection SaveResults)
{
LinkDeviceAndProject Model = new LinkDeviceAndProject();
Model.Devices = GetDevices();
Model.Projects = GetProjects();
foreach (var d in Model.Devices)
{
foreach (var p in Model.Projects)
{
string boxId = "d-" + d.Id.ToString() + "_p-" + p.Id.ToString();
if (SaveResults[boxId] != null)
{
string box = SaveResults[boxId];
bool boxValue = box == "true,false" ? true : false;
if (boxValue && d.Projects.Where(x => x.Id == p.Id).Count() == 0)
d.Projects.Add(p);
else if (!boxValue && d.Projects.Where(x => x.Id == p.Id).Count() > 0)
d.Projects.RemoveAll(x => x.Id == p.Id);
}
}
}
return View(Model);
}
private List<Device> GetDevices()
{
return new List<Device>() { new Device() { Id = 1, Name = "Device1" }, new Device() { Id = 2, Name = "Device2" } };
}
private List<Project> GetProjects()
{
return new List<Project>() { new Project() { Id = 1, Name = "Project1" }, new Project() { Id = 2, Name = "Project2" } };
}
}
Device Model:
public class Device
{
public int Id { get; set; }
public string Name { get; set; }
public List<Project> Projects = new List<Project>();
}
Project Model:
public class Project
{
public int Id { get; set; }
public string Name { get; set; }
public List<Device> Devices = new List<Device>();
}
LinkDeviceAndProject (View Model):
public class LinkDeviceAndProject
{
public List<Project> Projects = new List<Project>();
public List<Device> Devices = new List<Device>();
}
View:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<testchecks.Models.LinkDeviceAndProject>" %>
<!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>
<% using (Html.BeginForm())
{ %>
<div>
<table>
<tr>
<td></td>
<% foreach (var p in Model.Projects)
{%>
<td><%: p.Name%></td>
<%} %>
</tr>
<% foreach (var d in Model.Devices)
{ %>
<tr>
<td><%: d.Name%></td>
<% foreach (var p in Model.Projects)
{ %>
<td><%: Html.CheckBox("d-" + d.Id.ToString() + "_p-" + p.Id, d.Projects.Where(x => x.Id == p.Id).Count() > 0 ? true : false)%></td>
<%} %>
</tr>
<%} %>
</table>
<input type="submit" value="Save" />
</div>
<%} %>
</body>
</html>