How do I mimic ASP.NET AjaxOptions delegate functions?

When using the helper Ajax.BeginForm()

in, ASP.Net MVC

I can pass parameters with the names of different functions, for example, one to run OnBegin

, one to OnSuccess

, etc. How it works "under the hood"

The reason I am asking is because I am extending this to provide an alternative JQuery

and I need to figure out how to get from the method name given in the string JSON

in order to actually call them.

The class AjaxOptions

has a serialization method in which it wraps the method name like this (in this example, the property is AjaxOptions

OnSuccess

set to mySuccessFunction(p)

:

onSuccess: Function.createDelegate (this, mySuccessFunction (p))

I created my own class JQueryAjaxOptions

that serializes in the same way (but with some additional options). So what I have in my method for submitting the form is the above property as part of the json object and I need to be able to call the function.

How can i do this?

+1


source to share


1 answer


I found the answer to my problem:

What it really boiled down to was executing a line of code contained in a string variable. This can be easily done using the "eval (x)" syntax. The following example works for the onSuccess property:



eval (settings.onSuccess)

Sometimes you just need to think about one more step backwards to understand what you are trying to do and how easy it is =)

+1


source







All Articles