Rajesh Rajesh - 4 months ago 23
jQuery Question

How to Hide Ajax.ActionLink after call is made

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


I want to hide the link after the ajax call is made. I tried doing it onsuccess and oncomplete methods but i was not able to do it.
Any solution for this.

This is the way which i tried onsuccess, i was able to hide it but i am getting an error.

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


onsuccess function

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


This is working fine but,I am getting an error saying,

Microsoft JScript runtime error: 'b' is null or not an object

Answer

Try like this:

<%= 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() 
    }
) %>

and then:

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