C# 无法隐式转换ApplicationUser
我收到一个错误,说明我无法将类型ApplicationUser隐式转换为Customers模型。C# 无法隐式转换ApplicationUser,c#,asp.net-core,asp.net-core-identity,C#,Asp.net Core,Asp.net Core Identity,我收到一个错误,说明我无法将类型ApplicationUser隐式转换为Customers模型。 注意ApplicationUser正在使用Microsoft ASPNET标识。我基本上想添加注册到我的客户集合的新用户,这使他们与我的客户集合不同。目前,注册的新用户不属于这两个类别 [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<IActionResult> Register(Regis
注意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);
}
[HttpPost]
[异名]
[ValidateAntiForgeryToken]
公共异步任务寄存器(RegisterViewModel模型)
{
if(ModelState.IsValid)
{
客户=新应用程序用户{UserName=model.Email,Email=model.Email};
var result=wait mUserManager.CreateAsync(客户、模型、密码);
if(result.successed)
{
等待mSignInManager.SignInAsync(用户,isPersistent:false);
返回重定向到操作(nameof(HomeController.Index),“Home”);
}
}
返回视图(模型);
}
您的应用程序用户似乎不是来自客户的
,因此此行无效:
Customer customer = new ApplicationUser { UserName = model.Email, Email = model.Email };
谢谢你的快速回复。。好的,但是我想将新创建的用户添加到我的customer类中Customer
派生自ApplicationUser
:公共类Customer{public int Id{get;set;}公共虚拟应用程序用户{get;set;}}
+1。我通过将ApplicationUser
更改为Customer
解决了这个问题:{public class AccountController:Controller{protected UserManager mUserManager;protected signmanager mSignInManager;protected ApplicationDbContext ApplicationDbContext;public AccountController(ApplicationDbContext上下文、UserManager UserManager、SignInManager SignInManager)
我想我也需要为客户端添加相同的内容。