Я пытаюсь использовать ajax.actionlink, чтобы удалить количество товаров в моей корзине.Я добавил ссылку ajax.action, которая отлично работает на моем локальном компьютере (с Visual Studio 2010), но не на моем сервере.Вот код:
@Ajax.ActionLink("-",
"RemoveQuantityFromProduct",
"ShoppingCart",
new { productId = item.Id.ToString() },
new AjaxOptions
{
UpdateTargetId = "AjaxMiniShoppingCart",
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
OnSuccess="toggleCart",
})
На моем локальном компьютере полученная ссылка: http://localhost:2565/shoppingcart/removequantityfromproduct/16
На моем сервере, однако, полученная ссылка вместо: http://www.domain.com/shoppingcart/removequantityfromproduct?productId=16
Обе ссылки работают на локальном компьютере, но обе ссылки приводят к ошибке 404 на сервере.
Кто-нибудь знает, почему URL-адрес отличается на сервере и локальном компьютере?Кто-нибудь может объяснить, почему маршрутизация работает на локальном компьютере, а не на сервере?
(я использую nopCommerce 2.1 в качестве основы для этого интернет-магазина.)
[РЕДАКТИРОВАТЬ: Исправил полученный URL: s.Я ввел URL-адрес для добавления продукта вместо URL-адреса для удаления продукта.] 2011-10-10 11: 23
[ПРАВКА добавила RouteProvider.cs из NopCommerce] 2011-10-10 11:30
//home page
routes.MapLocalizedRoute("HomePage",
"",
new { controller = "Home", action = "Index"},
new[] { "Nop.Web.Controllers" });
//products
routes.MapLocalizedRoute("Product",
"p/{productId}/{SeName}",
new { controller = "Catalog", action = "Product", SeName = UrlParameter.Optional },
new { productId = @"\d+" },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("RecentlyViewedProducts",
"recentlyviewedproducts/",
new { controller = "Catalog", action = "RecentlyViewedProducts" },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("RecentlyAddedProducts",
"newproducts/",
new { controller = "Catalog", action = "RecentlyAddedProducts" },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("RecentlyAddedProductsRSS",
"newproducts/rss",
new { controller = "Catalog", action = "RecentlyAddedProductsRss" },
new[] { "Nop.Web.Controllers" });
//comparing products
routes.MapLocalizedRoute("AddProductToCompare",
"compareproducts/add/{productId}",
new { controller = "Catalog", action = "AddProductToCompareList" },
new { productId = @"\d+" },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("CompareProducts",
"compareproducts/",
new { controller = "Catalog", action = "CompareProducts" },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("RemoveProductFromCompareList",
"compareproducts/remove/{productId}",
new { controller = "Catalog", action = "RemoveProductFromCompareList"},
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("ClearCompareList",
"clearcomparelist/",
new { controller = "Catalog", action = "ClearCompareList" },
new[] { "Nop.Web.Controllers" });
//product email a friend
routes.MapLocalizedRoute("ProductEmailAFriend",
"productemailafriend/{productId}",
new { controller = "Catalog", action = "ProductEmailAFriend" },
new { productId = @"\d+" },
new[] { "Nop.Web.Controllers" });
//catalog
routes.MapLocalizedRoute("Category",
"c/{categoryId}/{SeName}",
new { controller = "Catalog", action = "Category", SeName = UrlParameter.Optional },
new { categoryId = @"\d+" },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("ManufacturerList",
"manufacturer/all/",
new { controller = "Catalog", action = "ManufacturerAll" },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("Manufacturer",
"m/{manufacturerId}/{SeName}",
new { controller = "Catalog", action = "Manufacturer", SeName = UrlParameter.Optional },
new { manufacturerId = @"\d+" },
new[] { "Nop.Web.Controllers" });
//reviews
routes.MapLocalizedRoute("ProductReviews",
"productreviews/{productId}",
new { controller = "Catalog", action = "ProductReviews" },
new[] { "Nop.Web.Controllers" });
//login, register
routes.MapLocalizedRoute("Login",
"login/",
new { controller = "Customer", action = "Login" },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("LoginCheckoutAsGuest",
"login/checkoutAsGuest",
new { controller = "Customer", action = "Login", checkoutAsGuest = true },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("Register",
"register/",
new { controller = "Customer", action = "Register" },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("Logout",
"logout/",
new { controller = "Customer", action = "Logout" },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("RegisterResult",
"registerresult/{resultId}",
new { controller = "Customer", action = "RegisterResult" },
new { resultId = @"\d+" },
new[] { "Nop.Web.Controllers" });
//shopping cart
routes.MapLocalizedRoute("AddProductToCart",
"cart/addproduct/{productId}",
new { controller = "ShoppingCart", action = "AddProductToCart" },
new { productId = @"\d+" },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("ShoppingCart",
"cart/",
new { controller = "ShoppingCart", action = "Cart" },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("AjaxShoppingCart",
"cart/",
new { controller = "ShoppingCart", action = "Cart" },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("AddQuantity",
"shoppingcart/addquantitytoproduct/{productId}",
new { controller = "ShoppingCart", action = "AddQuantityToProduct", productId = UrlParameter.Optional },
new[] { "Nop.Web.Controllers" });
routes.MapLocalizedRoute("RemoveQuantity",
"shoppingcart/removequantityfromproduct/{productId}",
new { controller = "ShoppingCart", action = "RemoveQuantityFromProduct", productId = UrlParameter.Optional },
new[] { "Nop.Web.Controllers" });
Метод действия:
public ActionResult RemoveQuantityFromProduct(int productId)
{
Response.CacheControl = "no-cache";
Response.Cache.SetETag((Guid.NewGuid()).ToString());
var cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
foreach (var sci in cart)
{
if (productId.Equals(sci.Id))
{
if (sci.Quantity > 1)
{
_shoppingCartService.UpdateShoppingCartItem(_workContext.CurrentCustomer, sci.Id, sci.Quantity - 1, true);
}
else
{
_shoppingCartService.DeleteShoppingCartItem(sci, true);
}
}
}
//updated cart
cart = _workContext.CurrentCustomer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
var model = PrepareShoppingCartModel(new MiniShoppingCartModel(), cart, true);
return PartialView("AjaxMiniShoppingCart", model);
}