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?

BritishDeveloper
  • 13,219
  • 9
  • 52
  • 62
  • 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...) – bzlm Mar 10 '11 at 14:47
  • 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: http://sparkviewengine.com/ – bzlm Mar 10 '11 at 14:48
  • 1
    Take a look at this [thread](http://stackoverflow.com/questions/3828961/asp-net-mvc-3-razor-performance) about Razor performance. – goenning Mar 10 '11 at 14:50
  • @Oenning Why? Do you recommend that @British run RC2? ;) – bzlm Mar 10 '11 at 16:11
  • No. That thread show us that the MVC team is working on the Razor performance and it's getting better after each release. – goenning Mar 10 '11 at 16:47
  • 3
    possible duplicate of [Does Razor syntax provide a compelling advantage in UI markup?](http://stackoverflow.com/questions/4019740/does-razor-syntax-provide-a-compelling-advantage-in-ui-markup) – marcind Mar 10 '11 at 16:52

4 Answers4

6

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

Community
  • 1
  • 1
marcind
  • 52,944
  • 13
  • 125
  • 111
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)

GvS
  • 52,015
  • 16
  • 101
  • 139
  • 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...)* – bonCodigo Sep 26 '14 at 08:19
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.

BoxerBucks
  • 3,124
  • 2
  • 21
  • 26
  • I am talking about the View enginges. This will be used with ASP.NET MVC 3 – BritishDeveloper Mar 10 '11 at 15:03
  • 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. – BoxerBucks Mar 10 '11 at 15:05
-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 ;-)