@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. :)
});
});
});