我想要Identity user
的crud操作。当我点击提交按钮时,它会显示错误
ArgumentNullException:值不能为null。 参数名称:provider atMicrosoft.Extensions.DependencyInjection.ServiceProviderExtensions.GetRequiredService [T](IServiceProvider provider)
UserController中
public async Task<ActionResult> Edit([Bind("UserName,Id")] ApplicationUser formuser, string id, string RoleId)
{
// ViewBag.RoleId = new SelectList(RoleManager.Roles, "Id", "Name");
var userManager = serviceProvider.GetRequiredService<UserManager<ApplicationUser>>();
var user = await userManager.FindByNameAsync(formuser.Email);
user.UserName = formuser.UserName;
if (ModelState.IsValid)
{
await userManager.UpdateAsync(user);
return RedirectToAction("Index");
}
else
{
ViewBag.RoleId = new SelectList(RoleManager.Roles, "Id", "Name");
return View();
}
}