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

4

13

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?

Yehudi answered 10/3, 2011 at 14:32 Comment(6)
There's a recent slide somewhere from a recent web conference that shows that Razor has marginally worse performance than Web Forms for a typical page. So, no obvious difference there. (Would be interesting to try the stuff that really bogs down the Web Forms View Engine though, like deeply recursive partials...)Electromyography
Don't forget all the other nice View Engines. While Razor is the recommended successor to Web Forms for all ASP.NET web development (ASP.NET Web Pages in general, not just ASP.NET MVC), there's still Spark, which has a big following: sparkviewengine.comElectromyography
Take a look at this thread about Razor performance.Titrate
@Oenning Why? Do you recommend that @British run RC2? ;)Electromyography
No. That thread show us that the MVC team is working on the Razor performance and it's getting better after each release.Titrate
possible duplicate of Does Razor syntax provide a compelling advantage in UI markup?Standoff
S
6

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

Standoff answered 10/3, 2011 at 16:55 Comment(0)
H
2

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)

Hangup answered 10/3, 2011 at 14:39 Comment(1)
In a multi-user concurrent access environment, can we say MVC will render better and favour client-side compared to web forms? (We are in the middle of considering MVC to migrate asp.net 4.0 web form apps which uses third party web services and local/external dbs...the stuff like MVC is slow in client side, MVC doesn't have better server side controls scare us to sth...)Cockleboat
L
0

You may want to clarify the technologies you are talking about. In ASP.Net WebForms is a web framework just like ASP.Net MVC is a web framework. The Razor view engine is a new view engine that is a different option to the default view engine in ASP.Net MVC web framework applications.

The main benefit to the Razor view engine is that it makes writing dynamic content on your MVC views easier because you don't have to use the <% %> formatting like you do with the default view engine. There are other benefits and Scott Gu has a good blog about them here.

Lintel answered 10/3, 2011 at 14:54 Comment(2)
I am talking about the View enginges. This will be used with ASP.NET MVC 3Yehudi
I figured that, I just wanted to provide clarification to others reading the question. Check out the blog article as Scott Gu is the MS VP in charge of ASP.net and is basically the inventor of the ASP.Net MVC framework.Lintel
V
-1

Learning curves can be a bitch, but hang in there. The code is not just "prettier", it's cleaner, and let's you work in a modular fashion, you can inject html sections that let you reuse code, much like object oriented code, but using just HTML.

This cleaner code means that 500 unique lines are now just 20! As for view state you can still uses hidden fields, and once you learn to code without, it wont be missed.

VS2013 now has an MVC Razor sample project with F# that will get you up to speed in no time.

The same project in Razor with F# that uses 500 lines of code would require 5000 or more lines of C# and Webform code.

I would recommend you learn this new technology before a 16 year old intern takes your job ;-)

Vulgarize answered 28/5, 2014 at 15:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.