I need to pass some value to the View Component from the controller. I tried differently but it does not transmit. If I don't pass anything to the constructor then everything works fine, but when I try to pass it to the constructor it doesn't even call the ViewComponent
Controller:
[HttpGet]
public IActionResult AddToCart(int id)
{
return ViewComponent("Cart", new {id});
}
View Component:
public class CartViewComponent : Microsoft.AspNetCore.Mvc.ViewComponent
{
int gId;
public CartViewComponent(int id)
{
gId = id;
}
public IViewComponentResult Invoke()
{
return View();
}
}
idand take that as a parameter in the component instead of just an int.idinstead ofnew {id}?