Asp.net mvc 4 列出用户拥有的所有角色,这些角色包含在名称';负责任的';
我有一个有许多用户角色的网站。现在,当我按下按钮时,将显示用户的所有角色。我怎样才能让我只扮演那些名字中包含“Responsible”的角色 这是我在控制器中拥有的:Asp.net mvc 4 列出用户拥有的所有角色,这些角色包含在名称';负责任的';,asp.net-mvc-4,Asp.net Mvc 4,我有一个有许多用户角色的网站。现在,当我按下按钮时,将显示用户的所有角色。我怎样才能让我只扮演那些名字中包含“Responsible”的角色 这是我在控制器中拥有的: ViewBag.RolesForThisUser = Roles.GetRolesForUser(UserName); 这就是我的观点: @if(ViewBag.RolesForThisUser != null) { @foreach (string s in ViewBag.RolesForThisUser)
ViewBag.RolesForThisUser = Roles.GetRolesForUser(UserName);
这就是我的观点:
@if(ViewBag.RolesForThisUser != null) {
@foreach (string s in ViewBag.RolesForThisUser)
{
<li>@s</li>
}
}
@if(ViewBag.RolesForThisUser!=null){
@foreach(ViewBag.rolesforthis用户中的字符串s)
{
@
}
}
您可以添加if语句
@if(s.ToLower().Contains('responsible') {
<li>@s</li>
}
@if(s.ToLower().Contains('responsible')){
@
}
太好了,谢谢。