Identity用户管理入门二(显示用户列表)
2024-08-29 21:52:16
在Controllers中新建AccountController,并在构造方法(函数)中注入SignInManager,UserManager
UserManager 用户管理(注册,查找,修改,删除用户等)
SignInManager 用户登录管理(登录,注销等)
private readonly SignInManager<IdentityUser> _signInManager;
private readonly UserManager<IdentityUser> _userManager; public AccountController(SignInManager<IdentityUser> signInManager, UserManager<IdentityUser> userManager)
{
_signInManager = signInManager;
_userManager = userManager;
}
创建Index方法显示所有用户
public async Task<IActionResult> Index()
{
var user = await _userManager.Users.ToListAsync();
return View(user);
}
创建Index.cshtml视图
@model IEnumerable<Microsoft.AspNetCore.Identity.IdentityUser>
@{
ViewData["Title"] = "Index";
} <h1>Index</h1>
<a asp-action="Register">注册</a>
<table class="table table-bordered">
<tr>
<th>@Html.DisplayNameFor(u => u.Id)</th>
<th>@Html.DisplayNameFor(u => u.UserName)</th>
<th>@Html.DisplayNameFor(u => u.Email)</th>
<th>@Html.DisplayNameFor(u => u.PhoneNumber)</th>
<th>操作</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.Id</td>
<td>@item.UserName</td>
<td>@item.Email</td>
<td>@item.PhoneNumber</td>
<td><a asp-action="EditUser" asp-route-id="@item.Id" type="button" class="btn btn-success btn-xs">修改</a>
<a asp-action="Delete" asp-route-id="@item.Id" type="button" class="btn btn-danger btn-xs" size="">删除</a> </td>
</tr>
}
</table>
显示结果如下(默认没有任何用户,但不方便展示效果故手工新增数据)
最新文章
- 解决程序出现“terminate called after throwing an instance of &#39;std::bad_alloc&#39; what(): std::bad_alloc Aborted (core dumped)”的问题
- WebView一般用法总结
- ios设备相关
- Java Hotspot G1 GC的一些关键技术
- svn 文件夹 无法提交
- Spring 注入数据源
- AndroidService 深度分析(2)
- 上传代码到GitHub时,遇到错误:fatal,The Requested URL return error 403
- Java多线程缓存器简单实现
- PHP--最常用--必背函数总结!php学习者收藏必备!
- Python面向对象——重写与Super
- 《深入理解Java虚拟机》-----第6章 类文件结构——Java高级开发必须懂的
- 【python-appium】appium 关键字
- Learn to securely share files on the blockchain with IPFS!
- python 正则括号的使用及踩坑
- 【BZOJ4827】【HNOI2017】礼物
- Git:多人推送/抓取分支事项
- SQL语句报错,无法绑定由多个部分组成的标识符解决
- Python获取路径下所有文件名
- FPGA远程更新之限制条件
热门文章
- &#127942;(不要错过!)【CI/CD技术专题】「Jenkins实战系列」(3)Jenkinsfile+DockerFile实现自动部署
- 在阿里云上单机部署k8s
- 表单验证插件jquery-validation以及案例
- Jarvis OJ部分逆向
- 攻防世界pwn高手区——pwn1
- Git点赞82K!字节跳动保姆级Android学习指南,干货满满
- java常见面试题目
- Create Shortcut to Get Jar File Meta Information
- JVM G1GC的算法与实现
- 不懂Ribbon原理的可以进来看看哦,分析RibbonClientConfiguration完成了哪些核心初始操作