我的行动
[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[]