Javascript – Ajax ActionLink OnSuccess call javascript function with parameters, Error: Object required

ajaxasp.net-mvcjavascript

Using Ajax.ActionLink's OnSuccess-Event brings me some trouble.

As asked here the function cannot be called directly. I tried all the suggestions I found, I get a message "Object required". The javascript-function expects an event, which is nothing/null when I pass it the correct way.

Code snippets

Before:

 OnSuccess = "ListApi.ResetAddLink(window.event, '" + AdressListIndexName + "')",

After:

OnSuccess = "function(){ListApi.ResetAddLink(window.event," + AdressListIndexName + ");}",

The Function ResetAddLink:

ListApi.ResetAddLink = function(_evt, ListIndexName) {
evt = _evt || window.event;
var target = evt.target || evt.srcElement;

var Index = parseInt(document.getElementById(ListIndexName).value);
var Pre = target.href.substring(0, target.href.lastIndexOf("=") + 1);

Index = Index + 1;
document.getElementById(ListIndexName).value = Index;

target.href = Pre + Index;
}

Questions

  1. Is the new OnSuccess call correct?
  2. How do I pass the event to the function? Or how can I get the event?

I'm pretty new to Ajax and Javascript in general, maybe I miss just a little piece 🙁

Thanks for any help

Regards

PS: I know there are some troubles about adress and address, but I copy/pasted as it is for now.
I also noticed that the error only occurs in internet explorer, firefox seems to get the event.

Best Answer

Tried to pass the event but didn't work... so I changed the parameters and now I'm passing the required data from the event from outside.