Ropstah
Ropstah

Reputation: 17804

ASP.NET MVC - AjaxContext

I've tried to inspect the AjaxContext that ASP.NET-MVC uses on for instance Ajax Actionlinks and their onSucces, onComplete etc. clientside functions. But I don't understand very much of it... Where is the documentation on this thing?

Does anybody know how to I get the 'target' or 'srcElement' (e.target or window.event.srcElement) when I am in a onSuccess or onComplete javascript event?

<%=Ajax.ActionLink(
"LinkText", "Action", New With {.Controller = "ControllerName"}, 
New AjaxOptions With {
    .UpdateTargetId = "divElement", 
    .OnSuccess = "function(ajaxContext) {console.log(ajaxContext);}"
}) %>

Which results in:

<a 
    href="/Popout/ApplicationCodePopout"
    onclick="Sys.Mvc.AsyncHyperlink.handleClick(
        this, new Sys.UI.DomEvent(event), 
        { 
            insertionMode: Sys.Mvc.InsertionMode.replace, 
            updateTargetId: 'divElement', 
            onSuccess: Function.createDelegate(this, 
                function(ajaxContext) {console.log(ajaxContext);}
            )
        }
    );"
>LinkText</a>

Upvotes: 1

Views: 1392

Answers (3)

Kieron
Kieron

Reputation: 27107

You could change the onSuccess method to this:

<%=Ajax.ActionLink(
"LinkText", "Action", New With {.Controller = "ControllerName"}, 
New AjaxOptions With {
    .UpdateTargetId = "divElement", 
    .OnSuccess = "function(ajaxContext) {debugger;}"
}) %>

(Note the debugger keyword)

Then you can break into it using VS2008 (assuming IE, if you're using Firefox, then install Firebug as Jake said) and then you can use the quick watch window (in VS or equivalent in Firebug etc) to view the object and it's properties/ methods etc.

As for some documentation, check out this link to see the code comments, and this article for some more information.

Upvotes: 3

superlogical
superlogical

Reputation: 14950

I would also recommend reading jQuery in action. One of the best tech books I have ever read! Once you read that you will be able to start writing your own jQuery code and not have to worry about using a server side wrapper library that spits out javascript for you :)

Check it out http://www.scribd.com/doc/8635225/jQuery-in-Action

Upvotes: 0

superlogical
superlogical

Reputation: 14950

Okay so you need to get Firebug installed (If you havnot already done so do it now :) Now start using console.log in your code to help you find out what properties and functions each object has available. Try typing in console.log(document) - You can do this in the Console window in the textbox (next to the >>>). Notice how you can click on the links in the console to interigate and see what properties and functions the object has available.

Upvotes: 1

Related Questions