Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 338
codingbiz Avatar asked Jul 08 '12 04:07

codingbiz


People also ask

What is difference between asp net webform and ASP.NET MVC?

Asp.Net Web Form has built-in data controls and best for rapid development with powerful data access. Asp.Net MVC is lightweight, provide full control over markup and support many features that allow fast & agile development. Hence it is best for developing an interactive web application with the latest web standards.

Which is better MVC or Razor?

From the docs, "Razor Pages can make coding page-focused scenarios easier and more productive than using controllers and views." If your ASP.NET MVC app makes heavy use of views, you may want to consider migrating from actions and views to Razor Pages.

What is the difference between Razor and MVC?

A Razor Page is almost the same as ASP.NET MVC's view component. It has basically the syntax and functionality same as MVC. The basic difference between Razor pages and MVC is that the model and controller code is also added within the Razor Page itself. You do not need to add code separately.

Which is better ASP.NET or ASP.NET MVC?

ASP.NET requires less expertise than MVC and is much faster to develop web applications overall. Prior knowledge of HTML is not required. ASP.NET uses a more mature code-base and has a larger web control toolbox. It's more sensible to use ASP.NET if you are already relying on 3rd party UI controls.


1 Answers

This is a great question. First, lets characterize Razor.

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

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

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

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

Additional Links:

  • ScottGu's Blog - Introducing Razor
  • ScottGu's Blog - Introducing WebMatrix
  • ASP.NET Web Page with Razor Syntax (MSDN)
like image 60
Glenn Ferrie Avatar answered Sep 29 '22 15:09

Glenn Ferrie