Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor vs Webforms view engine for new ASP.NET MVC 3 site

Razor is prettier (and is new therefore cool).

Webforms is something I am already familiar with.

Naturally I would unquestionably go for the new thing to learn - Razor. But I have heard of two disadvantages that worry me:

  • can't easily reuse existing web forms controls - in the rare instance I may need to drag something across... I'll reiterate - 'RARE'
  • I hear it is less efficient at rendering (takes longer than web forms)

So what are the advantages of Razor over Webforms view engines when using ASP.NET MVC 3?

like image 676
BritishDeveloper Avatar asked Mar 10 '11 14:03

BritishDeveloper


People also ask

What is the difference between Razor and webforms?

Razor is simply one of the View Engines provided. The other one provided out-of-the-box is the "old" WebForms one (you can also write your own View Engine by the way). So Razor does not have the notion of code-behind which stays within the WebForms view engine boundaries. So this kinda says it all.

What is the difference between Razor View engine and ASPx view engine?

ASPX View Engine is the default view engine for the ASP.NET MVC that is included with ASP.NET MVC from the beginning. Razor View Engine supports System.Web.Razor. ASPX View Engine supports System.Web.Mvc.WebFormViewEngine. In Razor View Engine we use Layouts. In ASPX View Engine we use masterPages. In Razor View Engine we use PartialPage.

What is the difference between ASP NET MVC and web forms?

ASP.NET MVC is a framework for creating web applications with either the Web Forms or Razor engine using the Model-View-Controller (MVC) pattern. ASP.NET Web Forms is a framework for creating web applications using the Web Forms render engine.

What is a form view engine in MVC?

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.


2 Answers

This has already been addressed by the following question: Does Razor syntax provide a compelling advantage in UI markup?

like image 143
marcind Avatar answered Oct 21 '22 20:10

marcind


The Web form controls are already not very usable in Asp.Net Mvc. Since the MVC does not have the ViewState/Postback mechanism, and most controls need to use that. (Webforms: 0 Points, Razor 0 Points)

Syntax in @Razor is much prettier. (Webforms: 0 Points, Razor 1 Points)

Don't know about the performance. I think that the (one time) parsing and rendering is such a small step of the whole pipeline, this should not matter. And might be changed by future updates. (Webforms: 0 Points, Razor 0 Points)

like image 45
GvS Avatar answered Oct 21 '22 20:10

GvS