2012-12-28 29 views
0

嗨我正在嘗試使用ajax創建購物車。我有點卡住它是我第一次使用ajax.What我試圖做的是創建一個ajax.Actiolink將更新的量程內文本tag.Here是到目前爲止我的代碼:使用Ajax更新跨度。行動鏈接

//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> 

我想能夠採取的partialVieew中的數據,並更新跨度在頂部,當我點擊我的link.In我無法判斷AdToCart操作結果是否被調用。

我在做什麼錯herE?

回答

1

您在操作鏈接中使用Products,但在Url鏈接中使用Product,也許其中一個是錯誤的。

+0

產品是指ProductsController –

+0

所以你應該在AjaxOptions的網址 – MuriloKunze

+0

的URL中使用'Products'(複數)謝謝你是這個問題 –