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
}
这个怎么做?
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
}
这个怎么做?
@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. :)
});
});
});