Pomster
Pomster

Reputation: 15197

I want to display a PDF on a new page/window?

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?

Upvotes: 0

Views: 466

Answers (1)

Iridio
Iridio

Reputation: 9271

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

Upvotes: 2

Related Questions