A Consistent Look: Previous Next Chapter
A Consistent Look: Previous Next Chapter
With Web Pages it is easy to create a web site with a consistent layout.
A Consistent Look
On the Internet you will discover many web sites with a consistent look and feel:
With Web Pages this can be done very efficiently. You can have reusable blocks of content (content blocks),
like headers and footers, in separate files.
You can also define a consistent layout for all your pages, using a layout template (layout file).
Content Blocks
Many websites have content that is displayed on every page (like headers and footers).
With Web Pages you can use the @RenderPage() method to import content from separate files.
Content block (from another file) can be imported anywhere in a web page, and can contain text, markup,
and code, just like any regular web page.
Using common headers and footers as an example, this saves you a lot of work. You don't have to write the
same content in every page, and when you change the header or footer files, the content is updated in all
your pages.
This is how it looks in code:
Example
<html>
<body>
@RenderPage("header.cshtml")
<h1>Hello Web Pages</h1>
<p>This is a paragraph</p>
@RenderPage("footer.cshtml")
</body>
</html>
Run example
Layout Page:
<html>
<body>
<p>This is header text</p>
@RenderBody()
<p>© 2014 W3Schools. All rights reserved.</p>
</body>
</html>
These tools also save you a lot of work, since you don't have to repeat the same information on all pages.
Centralizing markup, style, and code makes web applications much more manageable and easier to
maintain.
_AppStart.cshtml
@{
WebMail.SmtpServer = "mailserver.example.com";
WebMail.EnableSsl = true;
WebMail.UserName = "[email protected]";
WebMail.Password = "your-password";
WebMail.From = "[email protected]";
}