title: Call server method without page reload with razor page
body: <p>In my .net core razor page project, i would like to call server side methods from a cshtml input without reloading the page. I'm still a newbie with razor pages.</p>
  
  <pre><code>.cshtml : 
  
  input type="submit" id="AddCart" asp-page-handler="AddToCart" hidden
  
  Some JS to .click() the input.
  
  .cs :
  public async void OnPostAddToCart()
  {
  //code
  }
  </code></pre>
  
  <p>So far i did not find a way to prevent the page reload and still access my server-side methods.</p>
  
  <p>Thanks</p>
  
  <p>EDIT : 
  Looking at the link provided by brad, i managed to make it work.</p>
  
  <p>I added @Page "{handler?}" to write the url without the handler (not sure if it matters for ajax),
  I set my ajax url to "thePage/theMethod",
  I decorated my razor controller class with [ValidateAntiForgeryToken]
  And mentioned the anti forgery token in ajax :</p>
  
  <pre><code>$.ajax({
                  url: "/mainPage/AddToCart",
                  type: "POST",
                  contentType: "application/json; charset=utf-8",
                  beforeSend: function (xhr) {
                      xhr.setRequestHeader("XSRF-TOKEN",
                          $('input:hidden[name="__RequestVerificationToken"]').val());
                  },
                  success: function () {
                      alert("success");
                  },
                  complete: function () {
                      alert("complete")
                  },
                  failure: function () {
                      alert("failure");
                  }
              });
  </code></pre>