简体   繁体   English

将ActionResult返回到对话框。 ASP.NET MVC

[英]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. 我想捕获它的结果并在页面上的对话框中进行处理-但我无法弄清楚如何返回页面来执行将对此负责的jQuery。 Any ideas? 有任何想法吗?

You can call Method() by just routing your jQuery .ajax() request to it. 您可以通过仅将jQuery .ajax()请求路由到Method()来调用它。 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. 由于它只是直接返回html,因此请确保将响应类型设置为符合预期,然后jQuery回调处理程序将必须处理生成的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 */
            }
      })
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM