【发布时间】:2013-12-03 16:01:21
【问题描述】:
我有一个果园项目,我在 MVC 中创建了一个模块。我想使用 @Html.ActionLink 将特定用户的 id 传递给控制器,但它不调用控制器。这是我的代码:
在视图中:
@Html.ActionLink("100111", "AddToCart", "ShoppingCart", new { id = 101 }, null)
//also tried,
@Html.ActionLink("102829", "AddToCart", "ShoppingCart", new { id = 1, area = "OnlineShopping" },null)
在控制器中:
[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);
}
【问题讨论】:
-
您可能想要删除
[HttpPost]。由于[HttpPost],它没有调用控制器操作,并且单击锚标记实际上执行get。因此,请尝试从您的AddToCart操作中删除[HttpPost]属性装饰。
标签: c# asp.net-mvc razor orchardcms actionlink