Razor was able to identify the above statements as self-contained code blocks, and implicitly closed them for us.

One of the things my team has been working on has been a new view engine option for ASP. The codename for this new view engine is “Razor”, and we’ll be shipping the first public beta of it shortly. If you find something doesn’t work the way you want it to, you can swap it out for something else. NET MVC will include a new “Add-View” dialog that makes it easy for you to choose the syntax you want to use when you create a new view template file.

NET MVC has always supported the concept of “view engines” – which are the pluggable modules that implement different template syntax options. NET MVC today uses the same .aspx/.ascx/.master file templates as ASP. The new view-engine option we’ve been working on is optimized around HTML generation using a code-focused templating approach.

NET MVC view engines used today include Spark and NHaml.

We had several design goals in mind as we prototyped and evaluated “Razor”: We’ve spent the last few months building applications with it and doing lots of usability studies of it with a variety of volunteers (including several groups of non-. The feedback so far from people using it has been really great. It will allow you to easily select any of of the available view engines you have installed on your machine – giving you the choice to use whichever view approach feels most natural to you: Razor will be one of the view engine options we ship built-into ASP. All view helper methods and programming model features will be available with both Razor and the . You’ll also be able to mix and match view templates written using multiple view-engines within a single application or site.

Because the Razor parser understands the C# semantics in our code block, it was able to determine that the content should be contained within the foreach and treated like content that should be looped. Price statements element as server code – and execute them each time through the loop.

It also recognized that the trailing } terminated the foreach statement. Notice how Razor was smart enough to automatically close the @p. Price code blocks by inferring how the HTML and code is being used together.

The ability to code like this without having to add lots of open/close markers throughout your templates ends up making the whole coding process really fluid and fast.

For example, you could write some views using files, some with .cshtml or .vbhtml files (the file-extensions for Razor files – C# and VB respectively), and some with Spark or NHaml.

You can also have a view template using one view-engine use a partial view template written in another. Razor enables you to start with static HTML (or any textual content) and then make it dynamic by adding server code to it.

One of the core design goals behind Razor is to make this coding process fluid, and to enable you to quickly integrate server code into your HTML markup with a minimum of keystrokes.

To see a quick example of this let’s create a simple “hello world” sample that outputs a message like so: code nuggets, Razor does not require you to explicitly close the code-block: The Razor parser has semantic knowledge of C#/VB code used within code-blocks – which is why we didn’t need to explicitly close the code blocks above.