Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...