Saturday 28 September 2013

Razor View Engine

Recently me and my team has been working on has been a new view engine option for ASP.NET MVC4 WEB API, we should work new view engine Razor view. It’s new for every one including me. I see the samples; little impressed me I am trying to know about this.

WHAT?
Razor view was released for Microsoft Visual Studio 2010, Razor is a simple-syntax view engine and was released as part of ASP.NET MVC3 and the Microsoft WebMatrix tool set.
Razor is easy to learn and enables you to quickly be productive with a minimum of concepts. You use all your existing language and HTML skills. Razor doesn't require a specific tool and enables you to be productive in any plain old text editor –notepad to edit.
It’s not a new language, Supports "layouts" (an alternative to the "master page" concept in classic aspx pages).
The VS editor will also have the itellesense support that some of the other view engines don't have.
Declarative HTML Helpers also look pretty cool as doing HTML helpers within C# code reminds me of custom controls in ASP.NET. I think they took a page from partials but with the inline code.
HTML Encoding use @ block is automatically HTML encoded to better protect against XSS attack scenarios.
This is just Hello World Sample.
@{var message=”Hello World”;}
I Said : @message

i am try to compare Razor view and ASPX View engines, if may be missing any other point.

RAZOR View Engine
ASPX View Engine
The Razor View Engine is an advanced view engine that was introduced with MVC 3.0. This is not a new language but it is markup.
A web form view engine is the default view engine and available from the beginning of MVC
Razor has a syntax that is very compact and helps us to reduce typing.
The web form view engine has syntax that is the same as an ASP.Net forms application.
The Razor View Engine uses @ to render server-side content.
There is a different syntax ("<%: %>") to make text HTML encoded.
Razor does not require the code block to be closed, the Razor View Engine parses itself and it is able to decide at runtime which is a content element and which is a code element.
A web form View engine does not prevent Cross Site Scripting (XSS) attack.
The Razor Engine supports Test Driven Development (TDD).
Web Form view engine does not support Test Driven Development (TDD) because it depends on the System.Web.UI.Page class to make the testing complex.
There is only three transition characters with the Razor View Engine.
There are only three transition characters with the Razor View Engine.
The Razor View Engine is a bit slower than the ASPX View Engine.

Thanks Guys!! Hope you enjoy.....

3 comments: