我想在新页面上显示我的ActionResult的返回信息吗?
以下此电话是我无法在新页面上显示的唯一电话?
任何人都可以告诉我要添加什么来实现这一点,我已经使用Window.open和按钮,但现在我有一个RedirectToAction。
这是我想要在新页面/窗口上显示的电话:
return RedirectToAction("Print", new { id = contractInstance.SalesContractId });
我已经使用此代码执行此操作:
window.open('Contract/Print/' + $(this).attr('id'));
Print actionResult如下所示:
public ActionResult Print(int id) // sales contract Id
{
ParameterFields paramFields = CreateParameterFields(id); // pass the id of the contract
// Save the report run details
Guid reportRunId;
SaveReportRunDetails(paramFields, out reportRunId);
try
{
<<< Print code >>>
//Open a new page on this return would also be a good answer :)!!!!!!!
return File(arrStream, "application/pdf");
}
catch (Exception err)
{
ViewBag.ErrorMessage = err.Message;
return RedirectToAction("Edit", new { id = id, error = err.Message });
}
}
答案 0 :(得分:2)
您是如何从视图中获取“打印”操作的?它只是一个超链接@Html.ActionLink("Print", "Print")
吗?
.NET无法告诉您的浏览器从服务器打开一个新窗口,即通过HTML标记或javascript调用(例如Window.Open)在客户端完成。在新页面中打开链接的最简单方法是在HTML上指定目标属性。使用ActionLink助手,您的语法将是:
@Html.ActionLink("Print", "Print", "Contract", new{id = Model.SalesContractId}, new {target = "_blank"})
这应该是这样的:
<a href="/Contract/Print/4" target="_blank">Print</a>
答案 1 :(得分:-1)
您可以尝试在控制器操作中执行以下操作
Response.Write("<script type='text/javascript'>
window.open('YourViewName', '_blank');
</script>");
由于 Subraatam