title: Call Controller Action using Jquery
body: <p>I am trying to reload a particular 'div' () when the user adds a item to a shopping cart. I have some Jquery which I want to run on the click event. It needs to call a post action (which is working) and then reload everything within a "reload" div (only a render action). </p>
  
  <p>This reload piece seems to work also, but doesn't just reload the div, but also a portion of the current page. Given this it must be the jquery which is incorrect. Any help with what I have done wrong would be appreciated. </p>
  
  <p>I will try and include only the necessary pieces of code below:</p>
  
  <p>Load the partial view in the layout view:</p>
  
  <pre><code>&lt;div id="reload"&gt;
      @{Html.RenderAction("_PartialView","Controller");}
  &lt;/div&gt;
  </code></pre>
  
  <p>Link user clicks on. Click event listened for by Jquery:</p>
  
  <pre><code>&lt;p class="button"&gt;
      &lt;a href="#" class="AddToCart" data-id="@item.ItemId"&gt; Add To Basket&lt;/a&gt;  
  &lt;/p&gt;
  </code></pre>
  
  <p>Action called by the Jquery on click event:</p>
  
  <pre><code>[ChildActionOnly]
          public ActionResult _CartSummary()
          {
              var cart = ShoppingCart.GetCart(this.HttpContext);
  
              ViewData["CartCount"] = cart.GetCount();
  
              return PartialView("_CartSummary.cshtml");
          }
  </code></pre>
  
  <p>JQuery called on click event:</p>
  
  <pre><code>    $(function () {
      $(".AddToCart").click(function () {
          var addToCart = $(this).attr("data-id");
          if (addToCart != '') {
              $.post("/ShoppingCart/AddToCart", { "id": addToCart }).success(function() {
                  $("#cartSummary").fadeOut();
                  $("#cartSummary").fadeIn().load('@Url.Action("_CartSummary","ShoppingCart")');
              });
              return false;
          };
      });
  });
  </code></pre>
  
  <p>when calling the JQuery above, the url that is returned by <code>$("#cartSummary").fadeIn().load('@Url.Action("_CartSummary","ShoppingCart")')</code> is <code>localhost/Store/@Url.Action(%22_CartSummary%22,%22ShoppingCart%22</code>. As expected this url is not found. The correct url would be <code>localhost/ShoppingCart/_CartSummary</code>. Seems that @Url.Action is not being processed and just passed in as the name of the Action.</p>