Reputation: 15207
I would like the return of my ActionResult Displayed on a new page?
This call below is the only call i have not been able to display on a new page?
Can any one show me what to add to get this right, i have used Window.open with buttons but now i have a RedirectToAction.
This is the call i want displayed on a new page/window:
return RedirectToAction("Print", new { id = contractInstance.SalesContractId });
I have buttons already doing this with this code:
window.open('Contract/Print/' + $(this).attr('id'));
The Print actionResult looks as follows:
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 });
}
}
Upvotes: 1
Views: 7812
Reputation: 1
You can try following in controller action
Response.Write("<script type='text/javascript'>
window.open('YourViewName', '_blank');
</script>");
Thanks Subraatam
Upvotes: -1
Reputation: 39827
How are you getting to the Print action from your Views? Is it just a hyperlink @Html.ActionLink("Print", "Print")
?
.NET cannot tell your browser to open a new window from the server, that is done client side via the HTML markup or javascript calls (eg. Window.Open). The easiest way to open a link in a new page is to specify the target attribute on the HTML. Using the ActionLink helper, your syntax would be:
@Html.ActionLink("Print", "Print", "Contract", new{id = Model.SalesContractId}, new {target = "_blank"})
This should render something like this:
<a href="/Contract/Print/4" target="_blank">Print</a>
Upvotes: 2