'Does not contain definition for AddAsync()
I am working on .Net razor pages. I have created a form on submit of form i am handling it using a post handler in .cs file but i am getting an error. I can add AddAsync in my handeler. Error is:-
Severity Code Description Project File Line Suppression State Error CS1061 'object' does not contain a definition for 'AddAsync' and no accessible extension method 'AddAsync' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) youtubeproject C:\Users\lenovo\Desktop\MXN_INTERN\youtubeproject\youtubeproject\Pages\Categories\Create.cshtml.cs 22 Active
Here is my code of .cs file
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using youtubeproject.Model;
using youtubeproject.Data;
namespace youtubeproject.Pages.Categories
{
public class CreateModel : PageModel
{
public readonly ApolicationDbContext _db;
[BindProperty]
public Category Category { get; set; }
public CreateModel(ApolicationDbContext db)
{
_db = db;
}
public void OnGet()
{
}
public async Task<IActionResult>OnPost()
{
await _db.Category.AddAsync(Category);
await _db.SaveChangesAsync();
return RedirectToPage("Index");
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
