title: Asp.Net - How to call ActionResult with ajax
body: <p>I want to click "2" Ajax will call ActionResult and put new question up but not rerun page
  i have been trying two day but it haven't worked
  People help me, please
  ActionResult:</p>
  
  <pre><code>[HttpPost]
          public ActionResult BaiTestIQ(int id)
          {
              var cauhoi = from q in data.Questions
                           join a in data.Answers on q.MaTests equals "IQ"
                           where q.MaCHoi == a.MaCHoi &amp;&amp; a.keys == id
                           select new baitest()
                           {
                               Cauhoi = q.Noidung,
                               DAn1 = a.DAn1,
                               DAn2 = a.DAn2,
                               DAn3 = a.DAn3,
                               DAn4 = a.DAn4,
                               DAn5 = a.DAn5,
                               DAn6 = a.DAn6,
                           };
              return View(cauhoi);
          }
  </code></pre>
  
  <p>Function Ajax:</p>
  
  <pre><code>&lt;script&gt;
  function loadcauhoi(num) {
      $.ajax({
          dataType: "Json",
          type: "POST",
          url: '@Url.Action("BaiTestIQ","TestIQ")',
          data: { id: num },
          success: function (a) {
              // Replace the div's content with the page method's return.
              alert("success");
          },
          error: function (jqXHR, textStatus, errorThrown) {
              alert(errorThrown)} 
      });
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>In HTML:</p>
  
  <pre><code>&lt;li&gt;
    &lt;a href="javascript:;" onclick="loadcauhoi(2)"&gt;1&lt;/a&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/uSrjE.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>Thanks for reading</p>