2012-04-23 4 views
0
AjaxOptions ajaxMainArea = new AjaxOptions() { HttpMethod = "Post", UpdateTargetId = "main_area" }; 
@Ajax.ActionLink("new game", "Game", ajaxMainArea) 

자바 스크립트에서 클릭해야합니다.아약스 링크를 클릭하는 방법은 무엇입니까?

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

어떻게 수행하나요?

답변

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가로드되어 있다고 가정합니다. 나는 그런 링크가 일부 사용자 지정 물건을하고있는 경우

, 난 그냥 일반 ActionLink HTML 도우미를 사용하여이

@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. :) 
     }); 
    }); 
}); 
입니다 것입니다
관련 문제