Ajax 不起作用,我通过添加输入按钮进行了测试,它适用于该功能,但不适用于 ActionLink。我在我的 cshtml 上添加了 jQuery 包。我正在使用最新的 jQuery 版本 2.0。
这是我的代码:
看法:
<span> @Ajax.ActionLink(
"Name Ajax",
"ShowUser",
new
{
id = 1,
sort = "FullName"
},
new AjaxOptions
{
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "userGridDiv",
OnBegin = "myonbegin",
OnSuccess = "myonsuccess",
OnComplete = "myoncomplete",
OnFailure = "myonfailure"
},
new
{
@class = "grid-link",
}
)
/span>
@section scripts{
<script type="text/javascript">
$(document).ready(function () {
$("#animatedgif").hide();
});
function myonbegin() {
//show animated gif
alert("helloworld");
$("#animatedgif").show();
}
function myonsuccess() {
//disable animated gif
$("#animatedgif").hide();
}
function myonfailure() {
//disbale animated gif
$("#animatedgif").hide();
}
function myoncomplete() {
//disable animated gif
$("#animatedgif").hide();
}
</script>
}
控制器:
public ViewResult ShowUser(int id, string sort)
{
User obj = new User();
var model = obj.GetUsers(id, sort);
View("userView", model);
}