I have a orchard project, where I have created a module in MVC. I want to pass the id of particular user to controller using @Html.ActionLink but it not calling controller. Here is my code:
In view:
@Html.ActionLink("100111", "AddToCart", "ShoppingCart", new { id = 101 }, null)
//also tried,
@Html.ActionLink("102829", "AddToCart", "ShoppingCart", new { id = 1, area = "OnlineShopping" },null)
In Controller:
[HttpPost]
public ActionResult AddToCart(int id)
{
_shoppingCart.Add(id, 1);
return RedirectToAction("Index");
}
[Themed]
public ActionResult Index()
{
// Create a new shape using the "New" property of IOrchardServices.
var shape = _services.New.ShoppingCart();
// Return a ShapeResult
return new ShapeResult(this, shape);
}
It is not calling the action method because of
[HttpPost]
and clicking on anchor tag actually does aGet
. So try remove the[HttpPost]
attribute decoration from yourAddToCart
action.