Display page in MVC 3 without layout

I have a page that creates a table for printing. I need to show this page without my surrounding _Layout page, for ease of printing. A.

How should I do it?

+44
c # asp.net-mvc-3
May 20 '11 at 6:29 a.m.
source share
5 answers

Assuming you are using a razor viewer mechanism (you mentioned the layout, not the main page)

 @{ Layout = null; } 

Well, you should actually use a razor viewer mechanism, but the idea is simple anyway. Do not specify (delete) the link to the main page file in your aspx view and delete all ContentPlaceHolders, write all the content directly on the page. Or otherwise, if you do not want to remove them for some reason. Create a PrintMaster.master master page that contains only ContentPlaceHolders.

+104
May 20 '11 at 6:31
source share
— -

When you create a view, it allows you to change the main page. If you unchecked the box, the view does not have a master page, and you can change the entire page.

+2
May 20 '11 at 6:49
source share

If you need to support the display of results on the page, as well as to have a printable view, you can create a second view (for example, named PrintView ) that does not use the page layout and calls return View("PrintView"); from your controller.

+1
May 20 '11 at 6:37 a.m.
source share
 While creating a new view, you can uncheck the use layout checkbox. This will create you a view with layout as null. @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Test</title> </head> <body> <div> </div> </body> </html> 
+1
Jun 10 '16 at 17:03
source share

A standard print style action can be performed in several ways. 1. Use a different view with a print button that sets the layout to null, assuming you can match the razor.

To do this with CSS, you will need a separate css file that will be uploaded to print and hide your main pages. See various articles on css media print keywords for example: http://webdesign.about.com/cs/css/a/aa042103a.htm

In this case, used

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

with the key here is media = "print", which will use this css only when printing. A.

0
May 20 '11 at 7:04 AM
source share



All Articles