title: Call Action Method on button click ASP.NET MVC
body: <p>I am trying to get user input in button <code>click</code>. 
  When user insert number and press <code>Check</code>, it needs to return <code>xml</code> data type. 
  So in my <code>controller</code> I create <code>function</code> which will return a data for passing <code>ID</code></p>
  
  <pre><code>[ResponseType(typeof(AKONTA))]
          public IHttpActionResult GetAKONTA(string id)
          {
              AKONTA aKONTA = db.AKONTAS.Find(id);
              if (aKONTA == null)
              {
                  return BadRequest("Ne postoji A_KONTO pod tim rednim brojem");
              }
  
              return Ok(aKONTA);
          }
  </code></pre>
  
  <p>And In my <strong>View</strong> I have following</p>
  
  <pre><code>&lt;br /&gt;&lt;br /&gt;
  &lt;form&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;A_KONTO&lt;/label&gt;
          &lt;input type="text" class="form-control" aria-describedby="AKONTO BROJ" placeholder="Unesite broj AKONOTO"&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;a asp-action="Index" class="btn btn-primary" id="aKonto" action="@Url.Action("GetAKONTA", "Akontas")"&gt;Provjeri&lt;/a&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And I want to create in <code>btn</code> <code>click</code> when user pass <code>ID</code> it needs to return <code>XML</code> data format. </p>
  
  <p><a href="https://i.stack.imgur.com/XGYoj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XGYoj.jpg" alt="IMAGES"></a></p>
  
  <p>SO far I create a <code>JS</code> function, but I don't know <code>JavaScript</code> and don't know the logic how to pass <code>Controller Action Result</code> to <code>JS</code>. </p>
  
  <pre><code>  &lt;script&gt;
          $(document).ready(function () {
              $('#aKonto').click(function () {
                  document.getElementById("aKonto").onclick = function () {GetAKONTA()};;
              });
          });
      &lt;/script&gt;
  </code></pre>
  
  <p>If someone can help me I would be very thankful. 
  Cheers ! </p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>function aKontoSubmit() {
              $.ajax({
                  type: "GET",
                  url: 'api/Akontas',
                  //data: { id: id },
                  dataType: "xml",
                  success: function (result) {
                      // action to do after form submit
                  },
                  error: function () {
                      alert("Ne postoji AKONTO pod tim rednim brojem");
                  }
  
              });
          }
  
  **routeConfig**
  
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using System.Web.Routing;
  
  namespace AkontasWebApi
  {
      public class RouteConfig
      {
          public static void RegisterRoutes(RouteCollection routes)
          {
              routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
  
              routes.MapRoute(
                  name: "Default",
                  url: "{controller}/{action}/{id}",
                  defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
              );
          }
      }
  }
  </code></pre>