【问题标题】:How to Hide Ajax.ActionLink after call is made调用后如何隐藏 Ajax.ActionLink
【发布时间】:2011-10-04 20:46:25
【问题描述】:
<%: Ajax.ActionLink("View Code Status", "GetCodes", "BvIndex",
        new { id = o.Id },
        new AjaxOptions { UpdateTargetId = count.ToString() },
        new { @id = "h" + count.ToString()}) %>

我想在 ajax 调用后隐藏链接。我尝试在成功和完整的方法中执行此操作,但我无法做到。 任何解决方案。

这是我尝试成功的方式,我能够隐藏它但我收到错误。

<%: Ajax.ActionLink("View Code Status", "GetCodes", "BvIndex",
        new { id = o.Id },
        new AjaxOptions {
                    OnSuccess = "functionhide("+count+")",
                    UpdateTargetId = count.ToString()
        },
        new { @id = "h" + count.ToString()})%>

成功函数

function functionhide(count) {
            $("#h" + (count)).hide();
        };

这工作正常,但我收到一条错误消息,

Microsoft JScript 运行时错误:“b”为空或不是对象

【问题讨论】:

    标签: jquery asp.net-mvc asp.net-mvc-2


    【解决方案1】:

    试试这样:

    <%= Ajax.ActionLink(
        "View Code Status", 
        "GetCodes", 
        "BvIndex",
        new { id = o.Id },
        new AjaxOptions {
            OnSuccess = "functionhide",
            UpdateTargetId = count.ToString() // <-- Warning you are probably having invalid markup as ids cannot start with a number
        },
        new { 
            id = "h" + count.ToString() 
        }
    ) %>
    

    然后:

    function functionhide() {
        $(this).hide();
    }
    

    【讨论】:

    • 该死的,达林!你太快了!我一直认为this 关键字从OnSuccess 方法调用中引用了jqxhr 对象...这是改变了还是我一直错了?
    • @DMactheDestroyer, IIRC 这在 ASP.NET MVC 3 中发生了变化,因为它使用 jQuery 而不再是 MicrosoftAjax 库。
    【解决方案2】:

    简单的解决方案是使用 -

    OnComplete="javascript:this.style.display='none'"
    

    例如

    @Ajax.ActionLink(
      "Hide button before ajax",
      "myAction", 
      new AjaxOptions { OnComplete="javascript:this.style.display='none'" }
    )
    

    【讨论】:

      【解决方案3】:

      我发现这个Stack Overflow post 可能会帮助你...他们注意到收到相同的错误消息并将OnSuccess 值设为匿名函数似乎可以解决它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-01
        相关资源
        最近更新 更多