【发布时间】:2013-08-27 17:27:16
【问题描述】:
我的行动
[Authorize(Roles = "Admin")]
public ActionResult Index()
{
using (var ctx = new _dbContext())
{
return View(ctx.UserProfiles.OrderBy(x => x.UserId).ToList());
}
}
我想用 UserId 和 UserName 显示角色,我该怎么做??
更新: 查看模型
public class AccountIndexViewModel
{
public int UserId { get; set; }
public string UserName { get; set; }
public string Roles { get; set; }
}
查看
@using GoldCalculator.Models
@model IEnumerable<AccountIndexViewModel>
@foreach (var user in Model)
{
<tr>
<td>@user.UserId</td>
<td>@user.UserName</td>
<td>@user.Roles</td>
<td> @Html.ActionLink("X", "Delete", new { id = @user.UserName }, new { @class = "deletebtn"})</td>
</tr>
}
输出是 System.String[]
【问题讨论】:
-
显示它有什么问题?你不知道如何在视图中做到这一点或什么?
-
不知道如何进入角色.. 用户配置文件没有角色属性.. 我感觉很愚蠢,不知道为什么我粘贴了这段代码......只是想知道如何进入角色和在 Simple Membership 中使用用户名显示他们
标签: asp.net-mvc simplemembership