开发者

Return ActionResult to a Dialog. ASP.NET MVC

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?


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 */
            }
      })
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜