0

I have a print method that shows a PDF i want it showing in a new window!

This is what i want displaying on a new page, tab, window!!!

return File(arrStream, "application/pdf");

My Print method:

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 
                return File(arrStream, "application/pdf");
            }
            catch (Exception err)
            {
                ViewBag.ErrorMessage = err.Message;
                return RedirectToAction("Edit", new { id = id, error = err.Message }); 
            }
        }

This is a controller, and i can't mix client-side scripting with sever side code, if i had it in a link that points to this controller then even my errors would display on a new page, this would be bad and annoying for users.

How can i go about achieving my goal?

Alex Peta
  • 1,407
  • 1
  • 15
  • 26
Pomster
  • 14,567
  • 55
  • 128
  • 204

1 Answers1

2

To open the pdf in a new page simply use target="_blank" in the calling your method.

Looking at your code it don't seem that you are using a post, so a simple

<a href="..." target="_blank">text</a> 

should solve your problem

Iridio
  • 9,213
  • 4
  • 49
  • 71
  • This is a controller, and i can't mix client-side scripting with sever side code, if i had it in a link that points to this controller then even my errors would display on a new page, this would be bad and annoying for users. – Pomster Jun 15 '12 at 06:18
  • It's better that you explain it clearly in your question than – Iridio Jun 15 '12 at 06:21
  • One way would be to force the save dialog if everything is correct, but I don't think you can force that. I believe it only depends on the client browser's configuration – Iridio Jun 15 '12 at 06:27
  • I have validation, so i am already only saving when every thing is correct. but cant use window,open on the print because it runs the save, and you must be able to save and stay on the same page. The only clean place to put it is in my controller, but i cant find away to do this ... :| – Pomster Jun 15 '12 at 06:34