list 集合

时间:2021-04-14 13:07:28

1、Model

public class ROLE_FUNCTION
{

  //角色集合
  public List< ROLE> ROLES { get; set; }

  //角色权限集合
  public List<ROLEFUNCTION> ROLEFUNCTIONS { get; set; }
}

2、controller

  ROLE_FUNCTION R_F = new ROLE_FUNCTION();

//角色
  R_F.ROLES = db.ROLE.Where(p => p.ROLETYPE != "超级管理员").ToList();

  //角色权限
  R_F.ROLEFUNCTIONS = db.ROLEFUNCTION.ToList();

3、 视图

@model TRSLMS.Data.Models.ViewModel.ROLE_FUNCTION

@foreach (var role in Model.ROLES)
{
  <tr>
  <td class="font_left" width="15%">
  <div align="center">@role.ROLENAME</div>
  </td>
@{string s = null;}
  @foreach (var func in Model.ROLEFUNCTIONS)
{
  if (role.ID == func.ROLEID)
  {
  s += func.FUNCTIONNAME + " ";
  }
}

<td class="font_left width="70%" onclick="ShowRole('@role.ID','@role.ROLENAME')">
<div align="center">@s</div>
</td>
<td class="font_left" width="15%">
<div align="center">
<input type="button" onclick ="fun(@role.ID);" value =" 菜单授权"/>
|
<input type="button" onclick ="FunButton('@role.ID ','@role.ROLENAME ');" value =" 页面授权"/>
</div>
</td>
</tr>
}