0
我想在我的viewComponent中訪問applicationUser。但是,這不像一個繼承自「Controller」的普通類。ViewComponent中的應用程序用戶
有誰知道我可以如何從ViewComponent訪問ApplicationUser?
public class ProfileSmallViewComponent : ViewComponent
{
private readonly ApplicationDbContext _Context;
private readonly UserManager<ApplicationUser> _UserManager;
public ProfileSmallViewComponent(UserManager<ApplicationUser> UserManager, ApplicationDbContext Context)
{
_Context = Context;
_UserManager = UserManager;
}
//GET: /<controller>/
public async Task<IViewComponentResult> InvokeAsync()
{
//ApplicationUser CurrentUser = _Context.Users.Where(w => w.Id == _UserManager.GetUserId(User)).FirstOrDefault();
//Code here to get ApplicationUser
return View("Header");
}
}
「這doesn' t就像一個繼承自「Controller」的普通類一樣工作。「你能更明白爲什麼這個「不起作用」?你是否遇到異常?如果是這樣,請將異常詳細信息添加到您的問題。 – Steven