title: Calling Action in Razor Pages
body: <p>as a newbie to Razor Pages I have a question regarding calling methods from Razor Page. </p>
  
  <p>I have a method called subtractProduct defined in my domain model. </p>
  
  <p>In my Index Page code I define IActionResult sellProduct which calls subtractProduct on specified ProductId. But I have no clue how to call this method on my html page. I've tried a lot of combinations, but nothing seems to be working. Anyone knows how to deal with this? Any help is greatly appreciated!</p>
  
  <p>My domain model is: </p>
  
  <pre><code>public class Product
  
  {
      public int ProductId { get; set; }
      public int Quantity { get; set; }   
      ...
      public void SubtractProduct()
      {
          Quantity -= 1;
      }
  }
  </code></pre>
  
  <p>My Index Page code is:</p>
  
  <pre><code>public class IndexModel : PageModel
  {
      private readonly CfEshop.Data.ApplicationDbContext _context;
  
      public IndexModel(CfEshop.Data.ApplicationDbContext context)
      {
          _context = context;
      }
  
      public IList&lt;Models.Product&gt; Product { get;set; }
  
      public async Task OnGetAsync()
      {
          Product = await _context.Products
              .Include(p =&gt; p.Categories).ToListAsync();
      }
  
      public IActionResult sellProduct(int id)
      {
          var products = _context.Products;
  
          _context.Products.Find(id).SubtractProduct();
          return Page();
      }
  }
  </code></pre>
  
  <p>And finaly my Razor page:</p>
  
  <pre><code>@page
  @model CfEshop.Pages.Product.IndexModel
  &lt;h2&gt;Index&lt;/h2&gt;
  
  &lt;table class="table"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Product[0].Quantity)
              &lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          @foreach (var item in Model.Product)
          {
              &lt;tr&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.Quantity)
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;a asp-page-handler="SellProduct" asp-route="@item.ProductId"&gt;Sell Product&lt;/a&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          }
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>