0

我如何调用Index下面的第二个动作

public ActionResult Index()
{
}

[HttpPost]
public ActionResult Index(FormCollection collection, string nextButton)
{
}

从一个ActionLink?我正在尝试下面的代码但没有成功:

@Html.ActionLink("Buy Now", "Index", "Store", new {edition = "std", nextButton = ""}, new Dictionary<string, object> {{ "class", "button medium light" }})

谢谢。

4

1 回答 1

1

默认情况下,ActionLink 会生成一个锚链接,因此单击时将对端点执行 GET 请求。

您可以使用 jquery 使用 ajax 异步执行到操作端点的发布。

$.ajax({ 
    url: 'http://endpoint.com', 
    type: 'POST', 
    data: $('#form').serialize() //Add some post data however you want. 
});

或者,您可以使用表单发布端点。[ValidateAntiForgeryToken]如果使用表单,您还应该用它来装饰您的端点。如果使用 jquery 发布方式,您仍然可以在帖子上添加 AntiForgery 隐藏文件作为标题,并通过在自定义过滤器中检查标题来验证。

@using Html.BeginForm() {
    @Html.AntiForgeryToken()
    //Add some inputs to represent your model
    <button type="submit">Save</button>
}
于 2013-03-21T10:53:56.490 回答