Jquery 调用部分视图(mvc)后如何在新窗口中返回ajax调用
我希望在新窗口中打印结果,而不是在html标记中打印结果Jquery 调用部分视图(mvc)后如何在新窗口中返回ajax调用,jquery,asp.net-mvc,Jquery,Asp.net Mvc,我希望在新窗口中打印结果,而不是在html标记中打印结果 $('#ResultDiv').html(result); 您可以尝试以下功能: $.ajax({ type: "POST", data: { Employeeid: Employeeidv }, url: '@Url.Action("LoadContentInfo","Home")', success: function (result) { //print result in new
$('#ResultDiv').html(result);
您可以尝试以下功能:
$.ajax({
type: "POST",
data: { Employeeid: Employeeidv },
url: '@Url.Action("LoadContentInfo","Home")',
success: function (result) {
//print result in new window
}
当然,配置为阻止无限制打开弹出窗口的浏览器将阻止所有这些非法活动。就我个人而言,我会使用某种模态(如)来实现这一点,而不是尝试打开新的浏览器窗口。我们开始:
$.ajax({
type: 'POST',
data: { Employeeid: Employeeidv },
url: '@Url.Action("LoadContentInfo","Home")',
success: function (result) {
//print result in new window
var w = window.open();
$(w.document.body).html(result);
}
});
如果要在“新建”选项卡中打开:
$.ajax({
type: "POST",
data: { Employeeid: Employeeidv },
url: '@Url.Action("LoadContentInfo","Home")',
success: function (result) {
//Open url in new window
window.open("http://yourUrl/", "MyWindow", "height=300,width=300");
}
控制器具有返回PartialView的方法:
window.open("http://yourUrl", "_blank", "width=600,height=500");
MyPartialView代码如下所示:
public PartialViewResult CreatePartialView()
{
return PartialView("MyPartialView");
}
@praguan
它没有解决您的问题吗?我认为来自@DarinDimitrov
的响应应该被标记为一个答案——除非我在这里遗漏了什么。它对我有用。标记作为答案也会帮助其他用户(比如我自己)。如果这里遗漏了什么,你可能想指出它。
<h1>Hello World</h1>
<p>
This is a very nice web page.
</p>
<button id="NewBrowserBtn">New Browser</button>
$(document).ready(function () {
$('#NewBrowserBtn').on('click', function () {
window.open('/Home/CreatePartialView', '_blank', 'left=100,top=100,width=400,height=300,toolbar=1,resizable=0');
});
});