InfoWorld preview: WebMatrix ramps up ASP.Net development

Microsoft combines all-in-one installation, a gallery of templates, and coding shortcuts to speed dev and deployment of Windows-based websites

Page 2 of 4

While Razor's "inline coding" style, which mingles business logic with view code in one file, might seem a step backward, Razor supports a kind of templating in which you define content pages apart from layout pages, separating static content and display mechanics. Consequently, a single layout definition can be applied to multiple Web pages.

This scheme works with the help of the LayoutPage property. At the outset of a content page, you include a bit of Razor code that looks like:

@{ LayoutPage = "<path-to-layout>" ... }

This effectively binds a content page to its layout page. The layout page (typically stored in a shared folder) is also a CSHTML file, but is shot through with the HTML that specifies a page's visual structure, mixed with Razor rendering functions that fetch and incorporate the appropriate content from the content page. You might have this bit of HTML code in the layout page:


Meanwhile, in the initial Razor code of the content page, you'll find this:

PageData["title"] = "My Great Website";

The content page will also identify named sections, which are instantiated in their proper location (and style) by the layout page, with the assistance of the @RenderSection() Razor function.

The upshot is that multiple Web pages (content pages, in this case) use a single layout page, which not only imparts a consistent look and behavior to the pages within a layout group, but also promotes reuse by gathering layout code into a single file. In addition, the layout page can flexibly accommodate either the presence or absence of named sections among the content pages it services.

WebMatrix database workspace and deployment
Another important website ingredient is a back-end database. Just choose the database workspace in the IDE, define a new SQL Compact database for your site, and WebMatrix provides tools for creating a new table, modifying the schema of an existing table, viewing and editing a table's data directly, managing indexes, or issuing an SQL query against the database. As with other parts of WebMatrix, the IDE's database capabilities will get you started, but carry you only so far. It has none of the advanced features (such as user management) you'll find in full RDBMS management tools, but is sufficient for SQL Compact.

WebMatrix provides multiple "workspaces" in which you manage different aspects of your website. For example, the files workspace lets you work with folders and individual Web page files. In the database workspace, you can create a SQL database, view database table data, or issue SQL queries.
| 1 2 3 4 Page 2
From CIO: 8 Free Online Courses to Grow Your Tech Skills
View Comments
Join the discussion
Be the first to comment on this article. Our Commenting Policies