0
AjaxOptions ajaxMainArea = new AjaxOptions() { HttpMethod = "Post", UpdateTargetId = "main_area" };
@Ajax.ActionLink("new game", "Game", ajaxMainArea)

javascriptをクリックする必要があります。

function newgame(cost) {
    //here I need call ajax method
}

これを行う方法?

4

1 に答える 1

0
@Ajax.ActionLink("new game", "Game",null, ajaxMainArea,new { @id="aNewGame" })

スクリプトで、機能を要素にバインドします。

$(function () {
    $("#aNewGame").click(function (e) {
        e.preventDefault();
        $.get("YourController/ActionMethod", { yourData: "someValue" }, function (response) {
          //Do whatever with the reponse.
        });
    });
});

ページにjQueryがロードされていると仮定します。

そのようなリンクを使用してカスタム作業を行っている場合は、通常のActionLinkHTMLヘルパーを使用して、このような機能をバインドします。

@Html.ActionLink("new game", "Game",null,new {@id="aNewGame"})

スクリプトは

$(function () {
    $("#aNewGame").click(function (e) {
        e.preventDefault();
        $.post("YourController/ActionMethod", { yourData: "someValue" }, function (response) {
          $("#main_area").html(response);
          //If you want to do something else, you can do it here. :)
        });
    });
});
于 2012-04-23T16:12:21.280 に答える