返回的ActionResult一个对话框。 ASP.NET MVC [英] Return ActionResult to a Dialog. ASP.NET MVC

查看:99
本文介绍了返回的ActionResult一个对话框。 ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个方法。

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

 return View(viewname);
}

我无法控制的外部库的返回类型或方法。我想抓住它的结果和处理,在页面上的对话 - 但我无法弄清楚如何回到页面执行了jQuery,将对此负责。任何想法?

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?

推荐答案

您可以致电方法()仅通过路由你的jQuery 阿贾克斯( )要求它。因为它只是回归直线上升HTML,请确保您设置您的响应类型的期望,和那么你的jQuery的回调处理程序将要处理生成的HTML。例如,

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

这篇关于返回的ActionResult一个对话框。 ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆