【发布时间】:2020-08-10 18:23:52
【问题描述】:
我正在尝试为 ApplicationUser.cs 添加一个控制器,以便当管理员登录时,他们能够查看、编辑、删除 dbo.AspNetUsers 表中的任何记录,但是我认为我正在这样做它错了。运行时出现错误“NullReferenceException: Object reference not set to an instance of an object.”有什么想法吗?
管理员控制器:
public AdminController (ApplicationDbContext application)
{
_application = application;
[HttpGet]
public IActionResult ActiveUser() { return View();}
[HttpPost]
public async Task<ActionResult> ActiveUser(ApplicationUser Model)
{
var active = await _application.Users.FindAsync(Model.Email);
Model.IsActive = true;
active.IsActive = (Model.IsActive==true);
await _application.SaveChangesAsync();
return View();
}
查看:`@model ApplicationUser
<input asp-for="IsActive" class="form-control" />
<span asp-validation-for="IsActive" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-success">ok</button>`
【问题讨论】:
标签: sql-server asp.net-core entity-framework-core asp.net-core-mvc asp.net-core-identity