title: Run js method before posting Html.BeginForm
body: <p>I'm using <code>Html.BeginForm</code> in Razor View, this is a login form triggered by a button. Also, to this button, I have attached <code>onclick</code> event to get token with ajax from external rest api. I want to queue this (as I figured, button triggers 2 events asynchronous). </p>
  
  <p><strong>Is there any way, to make this api call before submiting form from html?</strong></p>
  
  <pre><code>&lt;section id="loginForm" class="form-signin"&gt;
      @using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { role = "form" }))
      {
          @Html.AntiForgeryToken()
          &lt;hr /&gt;
          @Html.ValidationSummary(true, "", new { @class = "text-danger" })
          @Html.TextBoxFor(m =&gt; m.Email, new { @class = "form-control" })
          @Html.ValidationMessageFor(m =&gt; m.Email, "", new { @class = "text-danger" })
  
          @Html.PasswordFor(m =&gt; m.Password, new { @class = "form-control" })
          @Html.ValidationMessageFor(m =&gt; m.Password, "", new { @class = "text-danger" })
          &lt;label&gt;
              &lt;div class="checkbox"&gt;
                  @Html.CheckBoxFor(m =&gt; m.RememberMe)
                  @Html.LabelFor(m =&gt; m.RememberMe)
              &lt;/div&gt;
          &lt;/label&gt;
          &lt;input type="submit" value="Sign in" id="loginBtn"class="btn btn-lg btn-primary btn-block btn-signin" /&gt;
      }
  &lt;/section&gt;
  </code></pre>
  
  <p>This is simple MVC5 snippet.</p>