In my project I have a component that displays a list of products in a specific group.
public class ProductListIncategoryViewComponent : ViewComponent
{
private IProductRepository productRepository;
public ProductListIncategoryViewComponent(IProductRepository repoprod)
{
productRepository = repoprod;
}
public IViewComponentResult Invoke(int priorityid)
{
MixProductView result = productRepository.SelectByCategory(priorityid);
return View(result);
}
}
Component input is groupID.
So I call the component twice to show the products of the two groups. for example:
@await Component.InvokeAsync("ProductListIncategory", new { priorityid = 3 })
@await Component.InvokeAsync("ProductListIncategory", new { priorityid = 4 }) //Error
I have an error when doing it two times in a row.
Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances. Object name: 'KuteCoredbContext
but There is no Erro when calling the component once
@await Component.InvokeAsync("ProductListIncategory", new { priorityid = 3 })
or when call component by other groupid
@await Component.InvokeAsync("ProductListIncategory", new { priorityid = 4 })