无法隐式转换ApplicationUser

时间:2018-11-17 22:24:21

标签: c# asp.net-core asp.net-core-identity

我收到一条错误消息,指出我无法从ApplicationUser类型隐式转换为Customers模型。
注意ApplicationUser使用Microsoft ASPNET身份。我基本上想添加注册到我的客户集合的新用户,这将他们与我的客户集合区分开来。目前,新注册的用户不属于任何一个类别。

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Register(RegisterViewModel model)
{
    if (ModelState.IsValid)
    {

        Customer customer = new ApplicationUser { UserName = model.Email, Email = model.Email };
        var result = await mUserManager.CreateAsync(customer, model.Password);
        if (result.Succeeded)
        {

            await mSignInManager.SignInAsync(user, isPersistent: false);                    
            return RedirectToAction(nameof(HomeController.Index), "Home");
        }

    }


    return View(model);
}

1 个答案:

答案 0 :(得分:1)

您的ApplicationUser似乎没有偏离Customer,因此该行无效:

Customer customer = new ApplicationUser { UserName = model.Email, Email = model.Email };