title: How to pass parameter to View Component via Asp .Net Core controller
body: <p>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</p>
  <p>Controller:</p>
  <pre><code>[HttpGet]
  public IActionResult AddToCart(int id)
  {
      return ViewComponent(&quot;Cart&quot;, new {id});
  }
  </code></pre>
  <p>View Component:</p>
  <pre><code>public class CartViewComponent : Microsoft.AspNetCore.Mvc.ViewComponent
  {
      int gId;
  
      public CartViewComponent(int id)
      {
          gId = id;
      }
  
      public IViewComponentResult Invoke()
      {
          return View();
      }
  }
  </code></pre>