开发者

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 th开发者_开发技巧e 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?


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


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)


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.


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 ;-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜