“Razor” the new ASP.NET View Engine

Because of my work with the www.forkcan.com and the traveling around Sweden talking about ASPEN a Silverlight 4, MVVM, RIA Services, Unity 2.0, MEF application I haven’t spend so much time with blogging.

“Razor” is a new view engine for ASP.NET, you can get more information about it on Scott Guthrie’s blog. Here is an example of a old server-side script block in ASP.NET:


<
h1><%: title %></h1> <% foreach (var item in items) {%> <span><%: item.FirstName %> <%: item.LastName %></span><br/> <%{%>

 

With “Razor” the above code can look like this:


<
h1>@title</h1> @foreach (var item in items { <span>@item.FirstName @item.LastName</span><br/> }


“Razor” uses a new file suffix “cshtml” or “vbhtml”, where the prefix is the language used in the file.

What I like the most with “Razor” is the new way to use expressions and the cleaner server-side code blocks.

 

If you want to know when I will publish a new blog post, then you can follow me on twitter: @fredrikn

2 Comments

  • I am really glad MS decided to do new view engine, looks way better than web forms, to bad they did not go with the more elegant spark view engine approach. Scott gu mentioned that they were working on making it easier to integrate 3rd party view enginges wih visual studio and get intellisense. I hope that is true.

  • Will it be in ASP.NET Razor possible to use ASP.NET Ajax?

Comments have been disabled for this content.