[英]Return ActionResult to a Dialog. 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 */
}
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.