Displaying a page in MVC 3 without layout
I have a page that generates a printable table. I need to show this page without my surrounding _Layout
page, for printer-friendliness.
How would I go about doing this?
Solution 1:
Assuming you use razor view engine (you mentioned layout, not master page)
@{
Layout = null;
}
Well actually you should use razor view engine but anyways, idea is simple. Do not specify (remove) master page file reference in your aspx view and remove all ContentPlaceHolders, write all content directly in page. Or there's another way if you don't wish to remove them for some reason. Make PrintMaster.master
master page which will contain nothing but ContentPlaceHolders.
Solution 2:
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>
Solution 3:
When you create the view it allows you to change the Master Page. If you unmark the checkbox, the view comes with no Master Page and you can modify the whole page.