views:

88

answers:

1

Given a method..

public ActionResult Method()
{
 // program logic
   if(condition)
   {
    // external library
    // external library returns an ActionResult
   }

 return View(viewname);
}

I cannot control the return type or method of the external library. I want to catch its results and handle that in a dialog on the page - but I cannot figure out how to get back to the page to execute the jQuery that would be responsible for it. Any ideas?

+2  A: 

You can call Method() by just routing your jQuery .ajax() request to it. Since it's just returning straight up html, make sure you set your response type to expect that, and then your jQuery callback handler will have to deal with the resulting html. For example,

$("#myButton").click({
   $.ajax({
            // Basic ajax request properties
            url: /* route to call Method() */,
            data: {}
            dataType: "html",
            type: "GET",
            success: function(objResponse){
                   alert(objResponse);    // alerts the html of the result
                   /* Deal with response here, put the html in a dialog */
            }
      })
});
womp
I think this is what I'm looking for - but it is still redirecting the user to a different page. Is there any way to stop that and force the contents of the page to render int he dialog?
Stacey
This is a jquery call so it shouldn't be redirecting you anywhere. Do you have the button navigating to a url?
Zaffiro