Assign a Javascript function to AjaxOptions OnSuccess property raise an error - ASP.NET MVC

浪子不回头ぞ 提交于 2019-12-30 08:14:47

问题


I'm using the Ajax.ActionLink helper to generate a link to delete a record. This is the code:

Ajax.ActionLink("Delete Image", "DeleteImage", new { id = item.Id },
                                               new AjaxOptions { HttpMethod = "Delete", OnSuccess = "Test()" } )

I'm assign a Javascript function (Test()) to the OnSucess property because I want to do some JQuery stuff, but when I click the Delete link this error message is raised

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

in the MicrosoftAjax.js file (Line 5, Column 62099). If I remove the OnSuccess property, everything works fine (even if the Test() function is empty, the same error is raised). Thanks for your help!


回答1:


OnSuccess = "Test()" 

you have to write it like this it is a callback...

OnSuccess = "Test"



回答2:


If you have to pass any parameter to the OnSuccess event you may have to write the funcion in this way.

OnSuccess = "function(){exampleFunction('" + param1 + "');}"



回答3:


To pass a parameter, an anonymous function won't work, you need to do something like this:

OnSuccess = String.Format("Test({0})", param)


来源:https://stackoverflow.com/questions/695729/assign-a-javascript-function-to-ajaxoptions-onsuccess-property-raise-an-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!