. Net mvc two view engines (Razor, Aspx), mvcrazor

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.