我在很多列出产品的页面中都有一个 WebGrid。我有以下代码将项目添加到用户单击的数据库中:
public bool ToCart(int userId,
string partNumber,
string productDescription,
int units,
int boxes,
decimal unitPrice,
decimal boxPrice,
decimal lineTotal,
string orderId,
DateTime dateTime,
bool isBoxed)
{
bool addedToCart = false;
try
{
Cart cart = new Cart()
{
UserId = userId,
PartNumber = partNumber,
Description = productDescription,
Units = units,
Boxes = boxes,
UnitPrice = unitPrice,
BoxPrice = boxPrice,
LineTotal = lineTotal,
OrderId = orderId,
OrderDate = dateTime,
IsBoxed = isBoxed
};
database.AddToCarts(cart);
database.SaveChanges();
addedToCart = true;
}
catch (Exception exception)
{
addedToCart = false;
Console.Write(exception.Message);
}
return addedToCart;
}
对该方法的调用如下所示:
ToCart(WebSecurity.CurrentUserId, PartNumber, ProductDescription, Units, Boxes, UnitPrice, BoxPrice, LineTotal, OrderId, DateTime.Now, IsBoxed)
现在我想把它变成一个 AJAX 帖子。但我不想要任何花哨的东西。我只想在将其添加到购物车时显示正常的 WaitCursor 或 BusyCursor,并<p>item added to cart</p>
在将其添加到购物车时在页面顶部显示 a 。
当用户点击他们希望添加到购物车的商品时,我该如何实现这一点?