3

In looking at the latest release of the Razor view engine with ASP.NET web pages, it looks nice because it has the full Razor support. So can someone give me a reasoning why I might want to choose ASP.NET Web Pages with the Razor view engine over traditional web forms, or its Razor view engine companion in ASP.NET MVC?

Per web pages, I'm speaking of this new web site framework available with VS 2010 SP 1: http://www.asp.net/webmatrix/tutorials/2-introduction-to-asp-net-web-programming-using-the-razor-syntax

Thanks.

3 Answers 3

3

The markup in razor is much more readable. When you have a product that already uses the web forms view engine, you can run razor side by side with it while you transition to razor views, which can be a lot of work in medium to larger sized projects. Keep in mind that during this transition, partials may be either razor or web forms, but a view and the master page it uses must use the same engine.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reminder about the master and web form using the same engine - I haven't run into that yet, but I wondered... :)
Yes, I agree, I'm asking in the context of the new ASP.NET web pages framework with Razor, where web forms have the razor syntax... though apparently there's no code-behind.
2

[Modified to answer the question posed in the title]

As an experienced developer, you would use the Web Pages framework when you want to get something done quickly (POC, for example), or if you want to teach someone how to get started with ASP.NET, perhaps.

You are asking two separate questions here: Web Forms View Engine vs Razor View Engine in MVC, and Web Pages Framework vs Web Forms Framework.

As others have said the first decision will be down to preference. Neither does anything that the other doesn't. It's a bit like the C# or VB debate.

The Web Pages framework is intended to provide an easier "in" for beginners than Web Forms or MVC. It can be considered a very belated replacement for the much easier classic ASP framework and it competes with PHP in that respect. If you need separation, testability and so on you should look to the MVC framework. The Web Pages framework doesn't offer very much at all in terms of enterprise development approaches.are used to Web Forms you are unlikely to gain anything from Web Pages. Separation is a lot more difficult. It doesn't encourage layering of code or testing. No server controls or code-behind files. And Web Pages only offers the Web Site deployment (compile on first run) as opposed to the Web Application which can be pre-compiled.

Razor itself was developed for the Web Pages framework. MVC liked it and leveraged it as a new view engine option. But essentially, you have three ASP.NET frameworks to choose from now: Web Pages, Web Forms and MVC.

6 Comments

I'm not asking two separate questions, I'm asking Web Pages Framework with Razor view engine vs. MVC + Razor View Engine.
Your question asks about Web Forms. You cannot use Razor with Web Forms.
OK, so that's a typo, but the title states it all.
And there was me thinking that the question said it all.
@MikeBrind actually you can instantiate and execute Razor classes in a very similar way that you load an UserControl i WebForms, so its not really true that you can't use Razor in WebForms. And since Razor classes just outputs pure text its easy to insert where ever you like on your WebForm Page stackoverflow.com/questions/8129712/…
|
1

The main reasons to choose Razor:

  • Terse - The HTML structure of your page is obvious, and doesn't have lots of <% and %> everywhere. (I like clean HTML. It tickles my OCD...)
  • Fluent - Simple transitions between server-side code and HTML without forcing you to explicitly context-switch.

2 Comments

I agree with your points. But now that ASP.NET web pages (not web forms) has razor syntax, would you use that over MVC's implementation?
Sorry, I didn't realize that was the question. That's really a "WebForms" vs. "MVC" question since the view engine is only a small part of the total equation. My personal preference is for MVC, though that really has little to do with Razor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.