1

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);
}
4

1 回答 1

0

您是否检查了从 google chrome 开发人员工具发送的请求。在Network页面中点击actionlink时。那必须为您提供线索。

你上面给出的代码对我来说很好用。另外请检查 Chrome 开发者工具中是否有任何 javascript 错误。您将在开发人员工具的右下角看到红色数字。

单击数字以查看错误的详细信息。或者将错误发布给我们分析和指导您。

于 2013-05-26T17:22:01.150 回答