[英]The name 'model' does not exist in the current context in ASP.NET Core
[英]How to access current User and database context in .net core Model
我有一個帶有方法的模型,我想獲取當前的 UserID 並可以訪問數據庫上下文。
public class Annonce
{
public int ID { get; set; }
...
public bool AnnonceDansFavoris(UserManager<ApplicationUser> UserManager)
{
// Recherche du user ID courant
string userID = UserManager.GetUserId(ClaimTypes.NameIdentifier);
var _context = (PatrimoineClickDbContext)ValidationContext.GetService(typeof(ApplicationDbContext));
return (_context.Favoris.Any(f => (f.CreePar == userID) && (f.AnnonceID == ID)));
}
}
但它不起作用:(
你能告訴我我該怎么做嗎?
謝謝
這是我的錯誤信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.