I am really lost on this as to how I am going to present and submit the data
I have the following database table
role table
role_id (pk)
role_name
permission table
permission_id (pk)
permission
role_permission table:
role_permission_id (pk)
role_id (fk from role table)
perm_id (fk from permission table)
edit_perm (bit)
view_perm (bit)
And based on the table, I have created the below view.
@using (Html.BeginForm("Update", "RolePermission", FormMethod.Post))
{
<div>
<table border="1">
<tr>
<th colspan="2">RoleName</th>
@if (Model.ListOfPermission.Count > 0)
{
foreach (var permitem in Model.ListOfPermission)
{
<th>@permitem.permission</th>
}
}
</tr>
@if (Model.ListOfRoles.Count > 0)
{
foreach (var roleitem in Model.ListOfRoles)
{
<tr>
<th rowspan="2">@roleitem.role_name</th>
<td>Edit</td>
@if (Model.ListOfPermission.Count > 0)
{
foreach (var permitem in Model.ListOfPermission)
{
<td>@Html.CheckBox("EditCheckBox")</td>
}
}
</tr>
<tr>
<td>View</td>
@if (Model.ListOfPermission.Count > 0)
{
foreach (var permitem in Model.ListOfPermission)
{
<td>@Html.CheckBox("ViewCheckBox")</td>
}
}
</tr>
}
}
</table>
<div>
<button id="SaveBtn" type="submit">Save</button>
</div>
</div>
}
and my model so far as below:
public class RolePermissionModel
{
public List <tblRole> ListOfRoles { get; set; }
public List <tblPermission> ListOfPermission { get; set; }
}
The above view gives the table format as the picture attached.
Sorry, I don't have enough reputation
My goal is to have check box checked depending on the role-permission table. above. For instance, if role-permission table has:
role_id: 1 -> (IT Admin role_id)
perm_id: 1 -> (Create User Permission)
edit_perm: 0
view_perm: 1
I need check checked on view sub-row of IT Admin row and Create User permission column.
Also, upon user clicking the checkbox and submit, I need to do insert.
The trouble here is, how do I pass the data from controller to view and how do I pass the view to controller to achieve that?
I am guessing I have to send the checkbox value along with column/row matching value to the controller on insert, but I have no idea how to achieve it. (Do I use jquery to get values of cell column value and row value?)
As for showing the checked value, I have no idea.
Your help will greatly be appreciated.