Run Your First Razor Code in WebMatrix

In this chapter you will learn
  • Write Your First Razor Syntax in WebMatrix
  • Execute Your Code
So, I think that the Overview of Razor Markup and WebMatrix has finished. It's time to do some practical based activity. In this chapter you will write your First Razor Syntax in WebMatrix and debug your program to see output. In the previous chapter you have already learned how to use WebMatrix to write Razor Markup.

Programming Example

In this programming Example, I will show the current date and time in the browser using C# and Razor Markup.  
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>        
        @{            
            string year,day,month,time;
            year=DateTime.Now.Year.ToString();
            day=DateTime.Now.DayOfWeek.ToString();
            month=DateTime.Now.Month.ToString();
            time=DateTime.Now.ToShortTimeString();
        }
 
        <h5>Current Year: @year</h5>
        <h5>Current Day : @day</h5>
        <h5>Current Month: @month</h5>
        <h5>Current Time: @time</h5>
    </body>
</html>

Output
Current Year: 2016
Current Day : Tuesday
Current Month: 8
Current Time: PM 05:43

Summary

This is just an example of razor markup to teach you how to debug program using WebMatrix. If you have successfully debugged this program at your PC and get desire output in web browser then you are absolutely ready to learn Razor Syntax.

More Articles

 

Share your thought