. Net mvc two view engines (Razor, Aspx), mvcrazor
ASPX
Advantages:Through the small comparison above, it is not difficult to see that ASP. net mvc is closely integrated to provide a better experience for ASP. NET developers in the past. In fact, it has several other advantages: ● Intelligent Sensing ● CodeDom provider that can be used in other languages (for example, C #, VB. NET, F #, Boo, Nemerle) ● views compiled or pre-compiled immediatelyDisadvantages:Of course, there are also disadvantages: ● Asp.net MVC can easily be confused with the classic Asp.net mode, and Asp.net MVC no longer supports them. (For example, ViewState PostBack) ● smart inductive forced styles are always not Inline code blocks. ● A simple template is messy.
Razor
Advantages:● Compact structure and smooth expressions ● easy to learn ● good intelligent perception ● Unit TestingDisadvantages:● Create a lightweight "tag group. Server-side labels actually provide structure code and non-server-side code around the server. Razor obfuscated HTML and server-side code. Development of pure HTML and JS is challenging. ● Syntax is very tricky to generate non-HTML content for HTML. In this case, Razor's data model is actually just String concatenation, with syntax and nesting errors, neither static nor dynamic detection, although VS. NET helps reduce this validation point during design. Maintainability and reconfiguration are also limited.
In short:If you are used to writing code on the front-end in WebForm, The aspx engine is more familiar. The Razor engine simplifies the input and can start to write code directly @, which is more concise. We recommend Razor to make the syntax more user-friendly.
A syntax code example.
Syntax name |
Razor syntax |
Aspx equivalent syntax |
Code block (server) |
@ {Int x = 123; string y = "test .";} |
<% Int x = 123; string y = "test."; %> |
Expression |
Encode: <p> @ model. Message </p> No encode: <p> @ Html. Raw (model. Message) </p> |
Encode: <p> <%: model. Message %> </p> No encode: <p> <% = model. Message %> </p> |
Combine text and markup Loops |
@ Foreach (var item in items) { <P> @ item. Prop </p> } |
<% Foreach (var item in items) {%> <P> <%: item. Prop %> </p> <% }%> |
Code and text Mixing |
@ If (foo) {<text> Plain Text </text>} @ If (foo) {@: Plain Text is @ bar} |
<% If (foo) {%> Plain Text <%} %> |
Server comment |
@ * This is a server side multiline comment *@ |
<% -- This is a server side multiline comment -- %> |
Call a method |
@ (MyClass. MyMethod <AType> ()) Use parentheses to clearly express what it is. |
|
Mixed expressions and text |
Hello @ title. @ name. |
Hello <%: title %>. <%: name %>. |