Razor Engine – part 1

Hello everyone,

have you heard about the Razor Engine?

If you work with MVC you are aware about view-engines. There is some view-engines like Spark and NHaml. Both can be used with .NET MVC 2, that means, NOT for .NET 4. As these two engines are open-sources, I suppose they gonna be avaible soon for .NET 4.

If you are interested in knowing better about the difference between these engines, take a look at this website.

Microsoft released the MVC 3. On this link you can download MVC 3 and read installation notes and requirements as well.

After installing MVC 3, open your Visual Studio and do the following steps (I’m using Visual Studio Express):

Creating a new project

Step 1

Step 2

Step 3

Note the dropdown with the Razor Engine. The other option is ASPX, what we don’t want and I’m going to show why.

So, now we have our solution ready to use Razor.

Open the file _Layout.cshtml (Yes, cshtml is the extension for razor files)

The _Layout.cshtml is how Razor calls the Master Page, that we know from ASP.NET.

It looks like that:

So that was the first part of the post about Razor. Only a simple example about how to create an MVC project using Razor.

Part 2 I’m going to show some advantages of Razor engine.

Tagged , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.