2

I am a newbie and just started learning the asp.net mvc, as I was going through the partial view tutorial and I created the small test application which is working fine.

I have a page which has a customers order and each item has an edit buttons for adding or deleting the items and by pressing it I can increase an item or delete an item from the cart. And for such action I am using

 HTML.actionlink("+", "AddToCart", "Orders", new { orderid=tempcart.orderid }, 
 new AjaxOptions()      
 { 
      OnBegin = "showplaces", 
      OnSuccess = "hideloader" 
 }, null); 

so when I click the button it goes to AddToCart() action and update the table in database but it doesn't update the partial view and the loader.gif stays forever on the page and don't call the hideloader() function.

Can you please tell me what's the problem?

Safran Ali
  • 4,477
  • 9
  • 40
  • 57
S.M.
  • 71
  • 7
  • 2
    I highly suggest you not to use Built in ajax stuff. It will do nothing other than confusing you. Use JQuery : http://stackoverflow.com/questions/578443/asp-net-mvc-ajax-with-jquery and http://iridescence.no/post/Invoking-ASPNET-MVC-Actions-from-JavaScript-using-jQuery.aspx are pretty good articles on this. – tugberk Aug 30 '11 at 08:23
  • 1
    can you please paste error stack trace or give more detail about the error. – Safran Ali Aug 30 '11 at 08:41

1 Answers1

3

1- First user Ajax.ActionLink as you are updating the partial view

2- One thing also place the cart's div id so it can get updated when action finishes.

3- And I had such problem once, so I did the following:

add OnFailure attribute in Ht

Ajax.ActionLink("+", "AddToCart", "Orders", new { orderid=tempcart.orderid }, 
 new AjaxOptions()      
 { 
      UpdateTargetId = "cart_divId", 
      OnBegin = "showplaces",
      OnFailure = "ShowDOMExcep", 
      OnSuccess = "hideloader" 
 }, null); 

and use this method to get DOM exception:

function ShowDOMExcep(context) {

    var html = context.get_data();
    var placeholder = context.get_updateTarget();
    $(placeholder).html(html);
    return false;
}

hope this helps ...

Safran Ali
  • 4,477
  • 9
  • 40
  • 57
  • 1
    @S First thanks for all pointer. Yes I found an error when regenerating the partial view. Thanks – S.M. Aug 30 '11 at 09:45