简体   繁体   中英

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

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.

试图通过事件,但是没有用...所以我更改了参数,现在我从外部传递了事件所需的数据。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM