Razor enables you to start with static HTML and then make it dynamic by adding server code to it. In other words, you can use C# alongside HTML to create a dynamic web page.
In this example, you have a for loop, and it creates an <li>
element on each iteration. This is better than having to type out the full <ul>
in static HTML for many reasons. Some reasons include:
- Easier to maintain and update
- Faster to develop
- You have the ability to perform complex (or preferably not-so-complex) calculations that can be inserted alongside static HTML
That code will output:
HTML
<ul>
<li>0</li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
</ul>
Rendered HTML
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
You can read more about what the Razor View Engine is here: http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx