Search code examples
asp.net-mvcrazorunobtrusive-javascript

Unbind @Ajax.ActionLink after success


I want to remove the Unobstrusive microsoft ajax @Ajax.ActionLink bind after click.

something like this:

.cshtml :

@Ajax.ActionLink("Edit", "EditDeliveryZones", new { idConnection = ViewBag.idConnection }, new AjaxOptions() { UpdateTargetId = "EditDeliveryZones" }, new { @class = "ajaxdialogopen" })

JavaScript:

$('.ajaxdialogopen').one('click', function (event) {
     $(this).off('click'); // THIS DOESNT WORK
     this.onclick = null; // THIS DOESN't WORK EITHER
}

Thanks!


Solution

  • How about putting something like this in your handler:

    $(this).removeAttr('data-ajax');
    

    I believe data-ajax is the attribute that the live handler triggers on, so removing it from the link should prevent it from being treated as an ajax link anymore.