如何更改身份3中的用户名?

时间:2016-04-08 07:55:53

标签: asp.net asp.net-mvc asp.net-core asp.net-identity-3

我想要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();
    }
}

0 个答案:

没有答案