Asp.Net Webforms Vs Asp.Net WebSite(Razor) Vs Asp.Net MVC
NickName:codingbiz Ask DateTime:2012-07-08T12:16:15

Asp.Net Webforms Vs Asp.Net WebSite(Razor) Vs Asp.Net MVC

I think Microsoft must have a reason for enhancing ASP.Net with RAZOR syntax.

On the Create New Website Project dialog of visual studio, there is another option for creating ASP.Net (Razor). The first time I came across the term Razor was when I read a book on Asp.Net MVC, I didn't know it exists for ASP.Net

enter image description here

I know what the Razor syntax is for, introduced in MVC 3. Before asking this question, I decided to create a test project for ASP.Net (Razor) and see how it is different from the normal ASP.Net webforms and ASP.Net MVC. I discovered no Model/View/Controllers folders like we have in MVC.

I discovered that the Master page is specified differently and the Master page is cleaner, no more <asp:ContentPlaceHolder />

But my questions are:

  • I notice it uses .cshtml, are there no more codebehinds?
  • similarities and differences between ASP.Net (Razor) and ASP.Net MVC
  • Can it be extended to function like ASP.Net MVC e.g. adding Controller?View/Model, Custom Routing I guess?
  • Why does this exist when we have ASP.Net MVC? Wouldn't this encourage reluctance to move to ASP.Net MVC?
  • and why would you choose ASP.Net+Razor over ASP.Net MVC?

UPDATE: ASP.NET Web Pages in particular was designed to make it easy for people who already know HTML to add server processing to their pages. It's a good choice for students, hobbyists, people in general who are new to programming. It can also be a good choice for developers who have experience with non-ASP.NET web technologies

Update ASP.NET Web Pages ASP.NET Web Pages targets developers who want a simple web development story, along the lines of PHP. In the Web Pages model, you create HTML pages and then add server-based code to the page in order to dynamically control how that markup is rendered. Web Pages is specifically designed to be a lightweight framework, and it's the easiest entry point into ASP.NET for people who know HTML but might not have broad programming experience — for example, students or hobbyists. It's also a good way for web developers who know PHP or similar frameworks to start using ASP.NET.

Asp.Net Web Pages

Please, I need your technical opinion. Thanks.

Copyright Notice:Content Author:「codingbiz」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/11380607/asp-net-webforms-vs-asp-net-websiterazor-vs-asp-net-mvc

Answers
Saeid Akbari 2014-05-14T09:37:08

Well, You have two options:\n\n\nUse WebForms: use out-of-the box, ready to use server-side controls(mixed markup and business codes) and use master pages and skins, but face some complexity involved of these conveniences! :)\nUse MVC: or use separated design model which gives you a more organized codebase. you can first make a design prototype, or first making a business codes, then building the other aspect, quite easy. even you can give the designer more control on his work, giving him/her the ability to do everything he/she wants.\n-> this one is my preferred choice because it gives me more control on my code, makes my code more concise and clean.\n\n\nIf you selected the MVC pattern, then you are faced with another options... View Engines\n\n\nOld MVC View Engine: it is not bad, but is a bit verbose\nRazor Engine: it does the same thing the #1 does, why you ever don't want to use it?! it replaces nothing of the MVC pattern. it is also more concise and easy, you have both the power of MVC and the simplicity of the Razor Engine. Razor is a smarter in-markup syntax, which helps you stay focused on your business, rather than writing \"<%\"s !\nby using razor syntax you are provided just a benefit, the full power of MVC is at your fingertips!\n\n\nYou can also write simple asp.net web pages just with razor(C# or VB) syntax. (just like php)\n\n\nMy personal choice would be MVC+Razor, The best combination!\n",


Paolo del Mundo 2012-07-08T04:23:53

\nThere are no \"code-behinds\" in MVC, period. What you have are controllers, which exist both for Razor and non-Razor.\nThey're just two different types of markup. (See next answer)\nIt's not replacing MVC, it's just another option. The traditional markup is very verbose. Razor syntax is succinct. \n",


Glenn Ferrie 2012-07-08T04:51:55

This is a great question. First, lets characterize Razor. \n\nRazor is an engine that parses server-side code an emits Html, just like ASP.NET Web Forms only with different and arguably more streamlined and terse syntax. \n\nRazor v. Web Forms Sidebar: In ASP.NET Web Forms you have to identify when you wanted to start writing server code with '<%' and then when you were done writing server code you needed to identify that with '%>'. I love ASP.NET Web Forms, but that's clunky. With Razor you identify when you want to start writing server code with '@' and then the next time you start writing a server tag (starting with '<') it \"figures out\" that you're done with server code. It's a more concise way to write html intermingled with some server code. \n\nASP.NET Web Pages is a framework for creating simple Web Applications. 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. \n\nUltimately the goal is to provide choice based on the sophistication of the application that is being built. Understanding each with assist you in making the correct choice for your application.\n\nAdditional Links:\n\n\nScottGu's Blog - Introducing Razor\nScottGu's Blog - Introducing WebMatrix\nASP.NET Web Page with Razor Syntax (MSDN)\n",


Simon Mourier 2012-07-15T14:25:34

In the MVC pattern, M is the Model, C is the Controller, and V is the View. So, quite naturally, in the ASP.NET MVC model, there is the concept of a View Engine. 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.\n\nSo this kinda says it all. Razor handles the View part of MVC (If you choose to use it instead of the WebForms one). It has nothing to do with M or C.\n\nPersonally, I would definitely go for the Razor View Engine if you choose the ASP.NET MVC pattern, or use plain WebForms without MVC, as Razor has been designed to be less verbose, more simple to use than the Webforms one. It's also simply more recent so it tries to be ... simply better :-)\n\nAs a side note, the Razor Parser can also be used outside of ASP.NET MVC. It's implemented in an assembly that does not rely on MVC nor Web assemblies at all. See here for more on this: http://www.west-wind.com/weblog/posts/2010/Dec/27/Hosting-the-Razor-Engine-for-Templating-in-NonWeb-Applications",


Ivo 2012-07-08T04:23:11

There are not code-behinds by default, but you can easily make your razor file inherits from your custom class:\n\n@inherits Index\n\n\nand then\n\npublic class Index : WebViewPage { }\n\n\n(More information here: http://www.compiledthoughts.com/2011/01/aspnet-mvc3-creating-razor-view-engine.html)\n\nThis is more like an old-fashioned way of doing web, more asp3-like. The difference with mvc is that mvc provides a huge framework that supports real world applications (using routing, controller and actions, and not just \"code there in the markup\").\n\nI think it exists for making things that are really simple, but I don't actually know...\n\nFinally, I would always chose asp.net mvc with razor.\n\nHope it helps",


More about “Asp.Net Webforms Vs Asp.Net WebSite(Razor) Vs Asp.Net MVC” related questions

Asp.Net Webforms Vs Asp.Net WebSite(Razor) Vs Asp.Net MVC

I think Microsoft must have a reason for enhancing ASP.Net with RAZOR syntax. On the Create New Website Project dialog of visual studio, there is another option for creating ASP.Net (Razor). The ...

Show Detail

What is the difference between ASP.NET Web Forms vs ASP.NET WebSite vs ASP.NET Web Application vs ASP.NET MVC?

I am getting confused with all the different project types for developing a web solution. What is the difference between ASP.NET Web Forms vs ASP.NET WebSite vs ASP.NET Web Application vs ASP.NET M...

Show Detail

ASP.net Webforms to MVC Migration

I am looking for a way to start the migration of asp.net webforms to an asp.net MVC project that allows the webform pages to be used, but keeps things clean for the new mvc structure. Many of the

Show Detail

Should I dive into ASP.NET MVC or start with ASP.NET Webforms?

I plan to pick up Silverlight in the future. Possibility of going into Microsoft WPF. Currently learning Objective-C 2.0 w/ Cocoa. I already know Pros and Cons of ASP.NET MVC vs ASP.NET Webforms. ...

Show Detail

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

Show Detail

Does ASP.NET mean ASP.NET WebForms?

I have worked with ASP.NET MVC 5.0 and that is the only ASP* technology I have ever seen or worked with. I even searched on Goolge and got more confused. For example in this book, what are they

Show Detail

Razor views in ASP.NET Webforms application

I am trying to convert my Asp.net Webforms application into an Asp.net MVC one. I wanted to know if i could have Razor views(.cshtml) and Aspx views(.aspx) coexist in the same application.If yes,th...

Show Detail

Redirecting from ASP.NET WebForms to MVC

We have a large existing ASP.NET WebForms application, but we are now moving over to MVC. Rather than go through a painful process of trying to integrate MVC into the existing app, we're looking at

Show Detail

Is it possible to create a website and avoid the built-in ASP.NET controls with ASP.NET Webforms but still get the same functionality?

Is it possible to create a website and avoid the built-in ASP.NET controls with ASP.NET Webforms but still get the same functionality? As stated on various websites, using built-in ASP.NET control...

Show Detail

ASP.NET Web Pages with Razor over ASP.NET MVC Razor Views

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...

Show Detail