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?
您正在使用Products
在动作链接,但您使用Product
的URL链接,他们却可能是错误的。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.