Where to Write Razor Code – WebMatrix and VS

Microsoft WebMatrix
In this chapter you will learn

  1. Where to Write Razor Code?
  2. Visual Studio and WebMatrix Tool
  3. Programming Example

In this chapter you will learn the interface there you can start writing razor code. If you are MVC developer then you can directly use Razor syntax in your project but if you are learner then we advise you to use Microsoft WebMatrix tool.

Advantages of Microsoft WebMatrix tool

  1. It is light weight and freely available at Microsoft site. When I have downloaded WebMatrix 3 it was only 17MB.
  2. Its interface is like Microsoft word but have Intellisense power.
  3. Quickly debug webpages with IIS and generate output in your favorite browser.
  4. It includes IIS Express, ASP.Net and SQL Server Compact.

How to install WebMatrix?

If Visual Studio 12 or earlier version is installed in your PC then you can directly download and install WebMatrix. WebMatrix looks for following prerequisites in your PC.

  1. .NET version
  2. IIS 7.5 or 8 (It doesn’t support IIS10 or later version)

  • Step 1: Download .Net Framework if you have not installed Visual Studio.

    You can download .net from here or search in google for latest version:
    Size : Around 50MB
    Download Link : https://www.microsoft.com/en-in/download/details.aspx?id=30653

    Step 2: Download IIS8 if you don’t installed Visual Studio 2012 or earlier Version.

    You can download IIS8 from here or search in google:
    Size: Less than 10MB
    Download Link : https://www.microsoft.com/en-in/download/details.aspx?id=34679

    Step 3: Download Microsoft WebMatrix.

    You can download WebMatrix from here or search in google:
    Size : Less than 20MB
    Download Link : https://www.microsoft.com/web/webmatrix/

    Note: If you are running Visual Studio 2015 then WebMatrix wouldn’t be installed because it strictly look for IIS7.5 or IIS8. Visual Studio 2015 uses IIS10. So, uninstall IIS10 from control panel and then install IIS8.

    Now, we assume your PC is configured with WebMatrix and you are ready to write Razor code.

    Step 1: Launch WebMatrix

    Step 1

    Step 2: Select New Empty Site

    Step 2

    Step 3: Click on Create New File link.

    Step 3

    Step 4: Select .CSHTML File. Give the name it index.cshtml and click OK.

    Step 4

    Now write the following code inside <body></body> and click Run button which is on Top Left corner of the application.

    Step 5



    1 Hello Razor. How Are You!

    2 Hello Razor. How Are You!

    3 Hello Razor. How Are You!

    4 Hello Razor. How Are You!

    5 Hello Razor. How Are You!

    Note: If you forget to rename the page name as index.cshtml then add page name followed by slash (/) in url.


    How to Write Razor Code with Visual Studio 2015

    If you have installed Visual Studio 2015 or you have updated Visual Studio 2012 then you can use these editors for writing Razor Code.

    Step 1: Launch Visual Studio 2015

    Step 2: Click File New Project

    visual 1
    Click Image to Zoom

    Step 3: Select Web ASP.Net Web Application. Give the name of your Project and click OK.

    visual 2
    Click Image to Zoom

    Step 4: Now select Empty website and click OK. Your project will open Visual Studio Code Editor.

    visual 3
    Click Image to Zoom

    Step 5: Go to Solution Explorer, right click on your project name and select Add New Item

    visual 4
    Click Image to Zoom

    Step 6: Select Web Razor in Left Pane and select WebPage(Razor V3) in Middle pane. Give the name index.cshtml and click Add button.

    visual 5
    Click Image to Zoom

    Now the index.cshtml page is open in visual editor. Write following code to test razor syntax and debug your program.

    visual 6
    Click Image to Zoom


    1 Hello Razor. How Are You!

    2 Hello Razor. How Are You!

    3 Hello Razor. How Are You!

    4 Hello Razor. How Are You!

    5 Hello Razor. How Are You!


    In this chapter you have learned both ways to write Razor code, Visual Studio and WebMatrix. Visual Studio is for Developer and once you’ll become master in razor and start developing your project, visual studio will be great tool for you. But for learning Razor, WebMatrix is best because it is easy and it doesn’t add any complexity. In the next all tutorial we will use WebMatrix for run Razor code.
    In the next chapter you will write your first Razor code in WebMatrix and Debug your program.

    Leave a Reply

    Your email address will not be published. Required fields are marked *