MVC 3 ASPX VS RAZOR View Engine

Hi i just downloaded MVC 3 and found an new view engine called “RAZOR”. How is it useful?

What benefits does it provide?

How is different from ASPX pages?

Where should one use RAZOR view engine?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Scott Gu covered most of your questions in his Razor introductory blog post:

The new view-engine option we’ve been
working on is optimized around HTML
generation using a code-focused
templating approach

  • Compact, Expressive, and Fluid: Razor minimizes the number of
    characters and keystrokes required in
    a file, and enables a fast, fluid
    coding workflow. Unlike most template
    syntaxes, you do not need to interrupt
    your coding to explicitly denote
    server blocks within your HTML. The
    parser is smart enough to infer this
    from your code. This enables a really
    compact and expressive syntax which is
    clean, fast and fun to type.
  • Easy to Learn: 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.
  • Is not a new language: We consciously chose not to create a new
    imperative language with Razor.
    Instead we wanted to enable developers
    to use their existing C#/VB (or other)
    language skills with Razor, and
    deliver a template markup syntax that
    enables an awesome HTML construction
    workflow with your language of choice.
  • Works with any Text Editor: Razor doesn’t require a specific tool
    and enables you to be productive in
    any plain old text editor (notepad
    works great).
  • Has great Intellisense: While Razor has been designed to not require
    a specific tool or code editor, it
    will have awesome statement completion
    support within Visual Studio. We’ll be
    updating Visual Studio 2010 and Visual
    Web Developer 2010 to have full editor
    intellisense for it.
  • Unit Testable: The new view engine implementation will support the ability to unit test views (without requiring a controller or
    web-server, and can be hosted in any unit test project – no special
    app-domain required).

Method 2

Difference Between Razor View Engine and ASPX View Engine in MVC

http://royalarun.blogspot.in/2013/12/difference-between-razor-view-engine.html

ASPX View Engine is the default view engine for the Asp.net MVC that is included with Asp.net MVC from the beginning.
Razor Engine is an advanced view engine that was introduced with MVC3. This is not a new language but it is a new markup syntax.

ASPX View Engine doesn’t support TDD (Test Driven Development)
Razor Engine supports TDD (Test Driven Development)

ASPX View Engine support design mode in visual studio means you can see your page look and feel without running the application.
Razor Engine, doesn’t support design mode in visual studio means you cann’t see your design page look and feel.

ASPX View Engine is faster than Razor Engine.
Razor Engine is little bit slow as compared to Webform Engine.

Syntax
Webform uses <% and %>
for example

< %: Html.ActionLink("SignUp", "SignUp") % >

Razor uses @ symbol
for example

@Html.ActionLink("SignUp", "SignUp")

ASPX View Engine does not prevent XSS attacks means any script saved in the database will be fired while rendering the page.
Razor Engine prevents XSS attacks(Cross-Site Scripting Attacks) means it encodes the script or html tags like <,> before rendering to view.

Method 3

Although a bit out of date qua syntax: ScottGu explains most of it.

Quick Syntax reference can be found on Haacked blog.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x