1

I need to pass in a function the clicked element using @Ajax.ActionLink, this function will be runing at OnSuccess, normaly in jQuery we use $(this), but with @Ajax.ActionLink does not work. Is there any other way of doing this ?

@Ajax.ActionLink(Model._friends, "HistoryFriends", "Notification", new AjaxOptions{UpdateTargetId="category-result", OnSuccess = "activeThis(this, '.ctg-active')",  OnFailure = "error"})

as you can see, I'm trying to pass this to the function activeThis(this, '.ctg-active'), but can't get it to work.

Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
Ricardo Binns
  • 3,228
  • 6
  • 44
  • 71
  • 1
    get the id, then use getelementbyid http://stackoverflow.com/questions/4825295/javascript-onclick-to-get-the-id-of-the-clicked-button – samuelesque Nov 30 '12 at 19:05
  • You're using a string for the callback definition. So you're not passing `this` into the function, `this` is evaluated whenever the string is evaluated. In regular jQuery, you can pass in the object you want to use as `this` as the `context` parameter to the `.ajax` function (http://api.jquery.com/jQuery.ajax/). You might be better off with a definition like this `OnSuccess = function() { activeThis(this, '.ctg-active') }, although I don't know anything about the Callback framework. – Frank van Puffelen Nov 30 '12 at 22:53
  • Also see this question and answer for an example of what dotsamuelswan suggests: http://stackoverflow.com/a/6803517/209103 – Frank van Puffelen Nov 30 '12 at 22:55

0 Answers0