title: Calling controller action from javascript in view
body: <p>I want to call action from view using JavaScript, but I can't do this:
  Here is my code:</p>
  
  <pre><code>@if (ViewBag.Status == true)
  {
     &lt;script language="javascript" type="text/javascript"&gt;
         if (confirm("Some message"));
         //And here i want to add action call
     &lt;/script&gt;
  }
  </code></pre>
  
  <p>I'm trying to use @Html.Action, but this ruined script code and confirm message didn't show.
  When I write it as shown here: <a href="https://stackoverflow.com/questions/8952953/calling-asp-net-mvc-action-methods-from-javascript">Calling ASP.NET MVC Action Methods from JavaScript</a>:</p>
  
  <pre><code>    @if (ViewBag.Status == true)
      {
         &lt;script language="javascript" type="text/javascript"&gt;
             if (confirm("Some message"));
             {
                   $.ajax({
                          url: 'MyController/MyAction',
                          data: { id: id },
                          success: function () {
                              alert('Added');
                          }
                   });
            }
         &lt;/script&gt;
      }
  </code></pre>
  
  <p>nothing changed. It displays confirmation dialog but don't calling method</p>