【问题标题】:jQuery ajax not working on ActionLinkjQuery ajax 在 ActionLink 上不起作用
【发布时间】:2013-05-19 21:28:33
【问题描述】:

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

【问题讨论】:

    标签: jquery c#-4.0 asp.net-mvc-4


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-12
      • 2015-05-07
      • 1970-01-01
      相关资源
      最近更新 更多