@ Html.ActionLink不起作用

Bhu*_*kla 1 c# asp.net-mvc actionlink orchardcms razor

我有一个果园项目,我在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)
Run Code Online (Sandbox Code Playgroud)

在控制器中:

[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);
    }
Run Code Online (Sandbox Code Playgroud)

PSL*_*PSL 8

它没有调用action方法,因为[HttpPost]并且单击anchor标签实际上是一个Get.因此,请尝试[HttpPost]AddToCart操作中删除属性修饰.

    [HttpPost]//<--Remove this
    public ActionResult AddToCart(int id)
    {
        _shoppingCart.Add(id, 1);
        return RedirectToAction("Index");
    }
Run Code Online (Sandbox Code Playgroud)