0

Index以下の2番目のアクションを呼び出すにはどうすればよいですか

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 に答える