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

鉴于一种方法..

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

我无法控制外部库的返回类型或方法。 我想抓住它的结果并在页面上的对话框中处理它 – 但我无法弄清楚如何返回页面来执行负责它的jQuery。 有任何想法吗?

您可以通过将jQuery .ajax()请求路由到它来调用Method() 。 由于它只是直接返回html,请确保将响应类型设置为期望,然后您的jQuery回调处理程序将不得不处理生成的html。 例如,

 $("#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 */ } }) });