我想访问Controllers文件夹中的某些数据并在Identity中使用它们。
我有2个具有相同代码的视图,第一个位于Views文件夹中,第二个位于Identity / Pages / Account / Manage中。第二个无效。
第一查看代码:
第二个查看代码:
@page
@using HireMe.Models
@using HireMe.ViewModels.Accounts
@using Microsoft.AspNetCore.Identity
@model HireMe.ViewModels.Accounts.UserIdViewModel
@inject UserManager<User> UserManager
@{
ViewData["Title"] = "User List";
Layout = "/Areas/Identity/Pages/_Layout.cshtml";
var index = 1;
}
@foreach (var user in this.ViewData["Users"] as IEnumerable<UserViewModel>)
{
<tr class="row">
<th class="col-md-1">@index</th>
<td class="col-md-5">@user.Username</td>
<td class="col-md-6">
<div class="form-inline text-center justify-content-around">
@if (await this.UserManager.IsInRoleAsync(this.UserManager.Users.FirstOrDefault(u => u.UserName == user.Username), "Admin"))
{
<form asp-controller="Accounts" asp-action="DemoteUser" method="post" class="form-horizontal text-center">
<input type="hidden" asp-for="Id" value="@user.Id" />
<button type="submit" class="btn btn-info text-dark" value="Demote">Demote</button>
</form>
}
else
{
<form asp-controller="Accounts" asp-action="PromoteUser" method="post" class="form-horizontal text-center">
<input type="hidden" asp-for="Id" value="@user.Id" />
<button type="submit" class="btn btn-info text-dark" value="Promote">Promote</button>
</form>
}