给出一种方法..
public ActionResult Method()
{
// program logic
if(condition)
{
// external library
// external library returns an ActionResult
}
return View(viewname);
}
我无法控制外部库的返回类型或方法。我想抓住它的结果并在页面上的对话框中处理它 - 但我无法弄清楚如何返回页面来执行负责它的jQuery。有什么想法吗?
答案 0 :(得分:2)
您只需将jQuery Method()
请求路由到.ajax()
即可致电$("#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 */
}
})
});
。由于它只是直接返回html,请确保将响应类型设置为期望,然后您的jQuery回调处理程序将不得不处理生成的html。例如,
{{1}}