views:

76

answers:

4

I working on a project and I would like to have a printer friendly version of the Views I have. Is there anybody who already did this and have some tips how to accomplish this? (what kind Routing is used, etc.)

I was thinking of making a PrintController. In the ActionResult of a method in the PrintController to return a View with a specific masterpage.

public ActionResult Index(string printView)
{
  return View(@"~/Views/Product/Index", "PrinterFriendly_MasterPage"); 
}

Stephan Walter doesn't advice to use this kind of redirecting (tip #24) because it is not the way MVC was meant to be.

On the View there will be a link to print the page, e.g.:
- normal link: www.example.com/product;
- print link: www.example.com/print/product;

I don't want to use javascript or AJAX. Just show the same View the user is watching, only with a different masterpage (which will have specific print stylesheets).

A: 

What about just creating a print css which will hide navigation and whatever else you don't want showing on a print.

see http://meyerweb.com/eric/articles/webrev/200001.html and http://www.alistapart.com/articles/goingtoprint/ for more info.

Mladen Mihajlovic
A: 

Don't create separate views. Just create a print specific CSS file using media=print in the link, and the browser should automatically use this CSS when printing.

Jason
A: 

Thanks for the quick reply, but I it is not exactly the way I want it. I already have specific css files for printing.

Take a look at the following Dutch website for example Normal View and Print View.

I want to have a link which displays the same View but with another masterpage. In the other masterpage I include the css files for printing.

So, the user gets a View which is almost the same as "Print preview" from the browsers menu.

The advantage of doing it this way is, it will comply to the WCAG standard.

patheems
In that case I would suggest adding "routes" to your question tags as well.
Mladen Mihajlovic
A: 

Why not just specify the "media" attribute in your css link?

<link href="normal.css" rel="stylesheet" media="screen" type="text/css" />
<link href="print.css" rel="stylesheet" media="print" type="text/css" />

That way you can use 1 masterpage but have both screen view and print view differently.

Johannes Setiabudi