使用Ajax.ActionLink更新span

时间:2012-12-28 12:52:23

标签: c# asp.net asp.net-mvc asp.net-mvc-3

您好我正在尝试使用ajax创建一个购物车。我有点卡住它是我第一次使用ajax。我想要做的是创建一个ajax.Actiolink,它将更新span标签的内部文本。到目前为止,这是我的代码:

 //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中的数据,并在单击链接时更新顶部的跨度。在我的情况下,我无法确定是否甚至调用了AdToCart操作结果。

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您在操作链接中使用Products,但您在Url链接中使用Product,可能其中一个错误。