用户列表预览

Controllers->AccountController.cs

      [HttpGet]
public IActionResult Index()
{
return View(_userManager.Users);
}
private void AddErrors(IdentityResult result)
{
foreach (var error in result.Errors)
{
ModelState.AddModelError(string.Empty, error.Description);
}
}

Views->Account->Index.cshtml

@model IEnumerable<ApplicationUser>
@{
ViewBag.Title = "Index";
} <div class="panel panel-primary">
<div class="panel-heading">
User Accounts
</div>
<table class="table table-striped"> <tr><th>ID</th><th>Name</th><th>Email</th></tr>
@if (Model.Count() == ) {
<tr><td colspan="" class="text-center">No User Accounts</td></tr>
} else {
foreach (ApplicationUser user in Model) {
<tr>
<td>@user.Id</td>
<td>@user.UserName</td>
<td>@user.Email</td>
<td>
@using (Html.BeginForm("Delete", "Account",
new { id = user.Id })) {
@Html.ActionLink("Edit", "Edit", new { id = user.Id },
new { @class = "btn btn-primary btn-xs" })
<button class="btn btn-danger btn-xs" type="submit">
Delete
</button>
}
</td>
</tr>
}
}
</table>
</div>
@Html.ActionLink("Create", "Create", null, new { @class = "btn btn-primary" })

删除

[HttpPost]
public async Task<ActionResult> Delete(string id) {
ApplicationUser user = await _userManager.FindByIdAsync(id);
if (user != null) {
IdentityResult result = await _userManager.DeleteAsync(user);
if (result.Succeeded) {
return RedirectToAction("Index");
} else {
return View("Error", result.Errors);
}
} else {
return View("Error", new string[] { "User Not Found" });
}
}

修改

Controllers->AccountController.cs

  [HttpGet]
public async Task<ActionResult> Edit(string id) {
ApplicationUser user = await _userManager.FindByIdAsync(id);
if (user != null) {
return View(user);
} else {
return RedirectToAction("Index");
}
} [HttpPost]
public async Task<ActionResult> Edit(string id, string email, string password) {
ApplicationUser user = await _userManager.FindByIdAsync(id);
if (user != null) {
user.PasswordHash =_userManager.PasswordHasher.HashPassword(user,password);
IdentityResult result = await _userManager.UpdateAsync(user);
if (result.Succeeded) {
return RedirectToAction("Index");
} else {
AddErrors(result);
}
} else {
ModelState.AddModelError("", "User Not Found");
}
return View(user);
}

Views->Account->Edit.cshtml

@model ApplicationUser
@{ ViewBag.Title = "Edit"; }
@Html.ValidationSummary(false)
<h2>Edit User</h2> <div class="form-group">
<label>Name</label>
<p class="form-control-static">@Model.Id</p>
</div>
@using (Html.BeginForm()) {
@Html.HiddenFor(x => x.Id)
<div class="form-group">
<label>Email</label>
@Html.TextBoxFor(x => x.Email, new { @class = "form-control" })
</div>
<div class="form-group">
<label>Password</label>
<input name="password" type="password" class="form-control" />
</div>
<button type="submit" class="btn btn-primary">Save</button>
@Html.ActionLink("Cancel", "Index", null, new { @class = "btn btn-default" })
}

Views ->Shared->_Layout.cshtml 加一个主跳转连接

  <div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a asp-area="" asp-controller="Home" asp-action="Index">Home</a></li>
<li><a asp-area="" asp-controller="Home" asp-action="About">About</a></li>
<li><a asp-area="" asp-controller="Home" asp-action="Contact">Contact</a></li>
<li><a asp-area="" asp-controller="Account" asp-action="Index">Account</a></li> //加这句

mvc core2.1 Identity.EntityFramework Core 用户列表预览 删除 修改 (五)的更多相关文章

  1. mvc core2.1 Identity.EntityFramework Core 用户Claims查看(七)

    添加角色属性查看 Views ->Shared->_Layout.cshtml <div class="navbar-collapse collapse"> ...

  2. mvc core2.1 Identity.EntityFramework Core ROle和用户绑定查看 (八)完成

    添加角色属性查看 Views ->Shared->_Layout.cshtml <div class="navbar-collapse collapse"> ...

  3. mvc core2.1 Identity.EntityFramework Core 配置 (一)

    https://docs.microsoft.com/zh-cn/aspnet/core/security/authentication/customize_identity_model?view=a ...

  4. mvc core2.1 Identity.EntityFramework Core 实例配置 (四)

    https://docs.microsoft.com/zh-cn/aspnet/core/security/authentication/customize_identity_model?view=a ...

  5. mvc core2.1 Identity.EntityFramework Core 注册 (二)

    Startup.cs-> Configure app.UseAuthentication(); //启动验证 Controllers->AccountController.cs 新建 us ...

  6. mvc core2.1 Identity.EntityFramework Core 导航状态栏(六)

    之前做的无法 登录退出,和状态,加入主页导航栏 Views ->Shared->_Layout.cshtml <div class="navbar-collapse col ...

  7. mvc core2.1 Identity.EntityFramework Core 登录 (三)

    Controllers->AccountController.cs 新建 [HttpGet] [AllowAnonymous] public async Task<IActionResul ...

  8. webapi core2.1 Identity.EntityFramework Core进行配置和操作数据 (一)没什么用

    https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.1&am ...

  9. Nodejs之MEAN栈开发(九)---- 用户评论的增加/删除/修改

    由于工作中做实时通信的项目,需要用到Nodejs做通讯转接功能,刚开始接触,很多都不懂,于是我和同事就准备去学习nodejs,结合nodejs之MEAN栈实战书籍<Getting.MEAN.wi ...

随机推荐

  1. laravel的日志服务

    日志服务使用: $app=app(); $log=$app->make('log'); $log->info('post_index',['data'=>'this is post ...

  2. 总结5条对学习Linux系统有帮助的经验心得

    作为国产手机中的代表厂商,OPPO一直走在国内的前沿.不仅手机出货量在国内遥遥领先,而且在国外也抢占不少的市场份额.前段时间,OPPO在台湾地区签下田馥甄和林宥嘉担任OPPO R9s的代言人外,在东南 ...

  3. [POJ3378]Crazy Thairs

    Problem 给你一个数列,让你求由五个元素组成的顺序对的个数. Solution DP:用DP[i][j]表示把第j个作为五元组中第i个的方案数 则DP[i][j]=sum{DP[k][j-1]} ...

  4. HTTP协议详细解析

    HTTP协议详解 HTTP协议(HyperText Transfer Protocol,超文本传输协议)是因特网上应用最为广泛的一种网络传输协议,所有的WWW文件都必须遵守这个标准. HTTP是一个基 ...

  5. 3.10 C++虚基类 虚继承

    参考:http://www.weixueyuan.net/view/6367.html 总结: 本例即为典型的菱形继承结构,类A中的成员变量及成员函数继承到类D中均会产生两份,这样的命名冲突非常的棘手 ...

  6. SharePoint Framework 企业向导(五)

    博客地址:http://blog.csdn.net/FoxDave SPFx解决方案是如何被构建出来的--很重要 SPFx为SharePoint开发者在设计.编译和部署SharePoint自定义解 ...

  7. ClickOnce 和管理员权限

    有些程序需要管理员权限需要运行,同时又想用ClickOnce进行发布,这时候就麻烦了,两者是互斥的. 解决方案是,去掉管理员权限的要求,可以进行发布. 程序启动的时候,加载程序员权限的请求. 代码如下 ...

  8. oracle 实例名,数据库名概念

    拷贝于https://www.cnblogs.com/ahudyan-forever/p/6016784.html 在实际的开发应用中,关于Oracle数据库,经常听见有人说建立一个数据库,建立一个I ...

  9. Sample Credential Providers

        Windows Vista Sample Credential Providers Overview Contents Terms of Use Release Notes SampleCre ...

  10. go语言求1到100之内的质数

    素数指在一个大于1的自然数中,除了1和此整数自身外,没法被其他自然数整除的数.换句话说,只有两个正因数(1和自己)的自然数即为素数(也叫质数).比1大但不是素数的数称为合数.1和0既非素数也非合数. ...