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

前端 未结 6 1353
名媛妹妹
名媛妹妹 2020-12-12 22:36

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 o

相关标签:
6条回答
  • 2020-12-12 23:06

    Well, You have two options:

    1. Use 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! :)

    2. Use 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. -> this one is my preferred choice because it gives me more control on my code, makes my code more concise and clean.

    If you selected the MVC pattern, then you are faced with another options... View Engines

    1. Old MVC View Engine: it is not bad, but is a bit verbose
    2. Razor 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 ! by using razor syntax you are provided just a benefit, the full power of MVC is at your fingertips!

    You can also write simple asp.net web pages just with razor(C# or VB) syntax. (just like php)

    • My personal choice would be MVC+Razor, The best combination!
    0 讨论(0)
  • 2020-12-12 23:09

    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.

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

    Personally, 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 :-)

    As 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

    0 讨论(0)
  • 2020-12-12 23:12

    To get out of all the confusion by webform, MVC, Razor, WebPages and lot more to come from microsoft, I prefer html-->javascript-->webapi.

    0 讨论(0)
  • 2020-12-12 23:15

    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)
    0 讨论(0)
  • 2020-12-12 23:21
    1. There are no "code-behinds" in MVC, period. What you have are controllers, which exist both for Razor and non-Razor.
    2. They're just two different types of markup. (See next answer)
    3. It's not replacing MVC, it's just another option. The traditional markup is very verbose. Razor syntax is succinct.
    0 讨论(0)
  • 2020-12-12 23:25

    There are not code-behinds by default, but you can easily make your razor file inherits from your custom class:

    @inherits Index
    

    and then

    public class Index : WebViewPage { }
    

    (More information here: http://www.compiledthoughts.com/2011/01/aspnet-mvc3-creating-razor-view-engine.html)

    This 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").

    I think it exists for making things that are really simple, but I don't actually know...

    Finally, I would always chose asp.net mvc with razor.

    Hope it helps

    0 讨论(0)
提交回复
热议问题