Nistor Alexandru
Nistor Alexandru

Reputation: 5393

Updatating a span with Ajax.ActionLink

Hi I am trying to create a shopping cart using ajax.I am kind of stuck it's the first time I use ajax.What I am trying to do is create an ajax.Actiolink that will update a Inner text of a span tag.Here is my code so far:

 //This is the span I want to update
 <span id="UpdateCart">0</span>

 @Ajax.ActionLink("Add To Cart" ,
                             "AddToCart" ,
                             "Products", 
                             new {
                                    ProductId = @products.ElementAt(0).Value
                                 },
                             new AjaxOptions{
                                               Url = "/Product/AddToCart",
                                               InsertionMode = InsertionMode.Replace,
                                               UpdateTargetId = "UpdateCart",

                                            })
  public ActionResult AddToCart(string ProductId)
    {
        if( User.Identity.IsAuthenticated ) {

            //CartHelperClass.AddToCart(ProductId);
            return PartialView();
        } else {
            return RedirectToAction("LogIn" , "Account" , new {
                returnUrl = "Products" , subCat = Request.QueryString["subcat"]
            });
        }     
    }

 //This is my PartialView code:
 <span id="UpdateCart">(5)</span>

I would like to be able to take the data inside the partialVieew and update the span at the Top when I click the link.In my case I can not tell if AdToCart action result is even called.

What am I doing wrong herE?

Upvotes: 0

Views: 189

Answers (1)

MuriloKunze
MuriloKunze

Reputation: 15583

You are using Products in the action link but your are using Product in Url link, maybe one of them is wrong.

Upvotes: 1

Related Questions