【发布时间】:2012-02-20 20:15:16
【问题描述】:
我有一个方法:
public ActionResult AddProductToCart(int productId)
{
var product = _productService.GetProductById(productId);
if (product == null)
return RedirectToAction("Index", "Home");
int productVariantId = 0;
if (_shoppingCartService.DirectAddToCartAllowed(productId, out productVariantId))
{
var productVariant = _productService.GetProductVariantById(productVariantId);
var addToCartWarnings = _shoppingCartService.AddToCart(_workContext.CurrentCustomer,
productVariant, ShoppingCartType.ShoppingCart,
string.Empty, decimal.Zero, 1, true);
if (addToCartWarnings.Count == 0)
//return RedirectToRoute("ShoppingCart");
else
return RedirectToRoute("Product", new { productId = product.Id, SeName = product.GetSeName() });
}
else
return RedirectToRoute("Product", new { productId = product.Id, SeName = product.GetSeName() });
}
您会看到被注释掉的行:我希望那里不触发任何重定向,而只是停留在发出此请求的同一页面上。
如果我输入return View() 就不好了,因为它会搜索具有此名称的视图,而此方法是添加到购物车的简单操作..
你能给我一个如何重定向到当前网址或留在同一页面上的解决方案吗?
【问题讨论】:
标签: asp.net-mvc-3 razor