Guidelines to use Razor Syntax

In this chapter you will learn

  1. Guidelines to use razor syntax
  2. Razor Programming Example

This is very important chapter which covers all the properties of Razor Markup. If you covered this chapter clearly you will learn half of Razor Markup. So, it is advisable to study this chapter twice for better understanding.

Guidelines to Use Razor Markup

1. Inline Markup – Use @ symbol to add Razor Markup in the page.

Example

Output

I am Single Line Statements

2. Code Block – Use @ {your c# code} to add code block in a page.

Example

Output

Sum of 5 + 10 = 15




  • 3. Inside block, each code statements must end with semicolon (;)

    Example


    4. Use var keyword for creating variable. You can also use c# data types or vb data types for creating variables.

    Example

    Output

    5 + 10 = 15

    5. Keep string in double quotation (” “) mark.

    Example


    6. C# code is case sensitive.

    Example

    Output

    Sum of 5+10=15

    7. You can use Objects in Razor Markup

    Example

    Output

    Url : http://localhost:47150/
    File Path : /
    Location : C:\Users\Steven\Documents\My Web Sites\EmptySite1\
    Request Type : GET

    8. You can use logic and decision making in Razor Markup

    Example

    Output

    It is greater than 5

    9. You can combine Text, HTML and Razor syntax in Code block at the same time.

    Example

    Output

    Hello Jack. You are 20 years old.

    10. Whitespace – Razors ignores extra white spaces so don’t worry about extra spaces.

    Example

    Output

    Hello Razor

    11. Line breaks – Razors ignores extra line breaks, so don’t worry about extra line breaks.

    Example

    Output

    Hello Razor

    12. Comments – You can comment like this @* your comment *@. All the comment must be inside @* and *@ symbol. It might be inline or multiline both.

    Example

    Summary

    In this chapter you learned the several important guidelines which will help you to write error free Razor markup language.


    Leave a Reply

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