をトリガしません、私のコントローラの署名である:ここでアクションはここ
public class CartController : Controller
{
public ActionResult Index()
{
CartViewModel cartViewModel = _cartRepository.GetCart(SessionVariables.CartId);
return View(cartViewModel);
}
public ActionResult List()
{
return View();
}
[Authorize]
public ActionResult AddToCart(int productId, int quantity = 1)
{
return RedirectToAction("Index");
}
[HttpPost]
[ActionName("AddToCart")]
public ActionResult AddToCartFromDetails(int productId = 0, int quantity = 1)
{
return RedirectToAction("AddToCart", new {productId , quantity});
}
}
は、Global.asaxの上の私のルートである:ここでは
routes.MapRouteLowerCase(
"AddToCart", // Route name
"products/addtocart/{productId}", // URL with parameters
new { controller = "Cart", action = "AddToCart", productId = UrlParameter.Optional } // Parameter defaults
);
は[HttpPost]アクションに行かない私のフォームです私CartController上:
@using (Html.BeginForm("AddToCart", "Cart", null, FormMethod.Post, null))
{
<div class="quantity-container">
<div>
Quantity :</div>
<input type="text" name="quantity" value="1" />
<input type="hidden" name="productId" value="@Model.ItemDetails.ItemMasterId" />
</div>
<div class="buy-btn-container">
<input type="image" src="@Url.Content("~/Content/Images/buynow_btn.png")" alt="Buy"/>
</div>
<div class="clear">
</div>
}
フォームは、上記の設定私のルートに解決されないためのURL:
/products/addtocart
はいますが、フォームがそのアクションを使用するように、私は[HttpPost]属性を持つ他の1をタグ付け:従って私は代わりにBeginRouteFormに切り替えます。 –