In an MVC
application I joined multiple tables and returned it from Controller
to View
as shown below:
| EmployeeID | ControlID | DoorAddress | DoorID | DoorName |
------------------------------------------------------------
| 921 | 1 | 1 | 101 | Door 1 |
| 921 | 1 | 2 | 102 | Door 2 |
| 921 | 1 | 3 | 103 | Door 3 |
| 921 | 1 | 4 | 104 | Door 4 |
------------------------------------------------------------
Controller:
public ActionResult Edit(int? id)
{
// Create and execute raw SQL query.
string query = "SELECT a.EmployeeID, a.ControlID, a.DoorAddress, t.DoorID, t.DoorName FROM TEmpAccess AS a " +
"INNER JOIN TDoor AS t ON a.ControlID = t.ControlID and a.DoorAddress = t.DoorAddress where EmployeeID = " + id.ToString();
IEnumerable<EmpAccessViewModel> data = db.Database.SqlQuery<EmpAccessViewModel>(query);
return View(data.ToList());
}
I want to bind DoorName
values (Door 1, Door 2, Door 3, Door 4) to a checkbox list
and let the user to select them. After that, I want to pass corresponding EmployeeID
, ControlID
, DoorAddress
, DoorID
values of the the selected door to the Controller
. For example if the user selects Door 1 and Door 3, then I will pass these values below to the Controller
:
| EmployeeID | ControlID | DoorAddress | DoorID |
-------------------------------------------------
| 921 | 1 | 1 | 101 |
| 921 | 1 | 3 | 103 |
-------------------------------------------------
By using razor
syntax or javascript
in the view, how can I do this? Thanks in advance.