我有一个像这样的Ajax.ActionLink:
@Ajax.ActionLink("Load Related Titles",
"AjaxLoadRelated",
"Shared",
new { RelatedComics = c.RelatedComic.RelatedTitles },
new AjaxOptions() { HttpMethod = "Get", UpdateTargetId = "divRelatedTitles", LoadingElementId = "divLoading", OnBegin = "ajaxLoadMoreBegin", OnFailure = "ajaxLoadMoreFailed", OnSuccess = "ajaxLoadMoreSuccess" })
目前我的OnSuccess功能如下:
function ajaxLoadMoreSuccess() {
...
}
我想向它提出一个论点:
function ajaxLoadMoreSuccess(myArg) {
...
}
这可能吗?
提前致谢
答案 0 :(得分:8)
这是可能的。 mvc ajax不显眼的脚本创建了一个匿名函数 有三个参数(对应于jquery ajax完整方法的参数) data,status,xhr并使用jquery ajax完整方法的参数调用该方法。例如:
...OnSuccess = "ajaxLoadMoreSuccess1('hello world')"
或者
...OnSuccess = "ajaxLoadMoreSuccess2(calc(), data, status, xhr)"
<script type="text/javascript">
function ajaxLoadMoreSuccess1(message) {
alert(message);
}
function ajaxLoadMoreSuccess2(x, data, status, xhr) {
$('#somespan').text('calc was ' + x + ' and data is ' + data);
}
function calc() {
return 1 + 2;
}
</script>