The difference between ASPX and razor

Source: Internet
Author: User

The two almost do not understand, now to choose one, only Baidu, and then a look, do not know which of you big God said right.

Two engine syntax is completely different, the performance of ASP. NET Advantage, syntax sugar is Razor's strength.

Development MVC3 Preferred Razor
Razor is the mainstream. Not the same syntax.
Razor Simplicity

Cshtml using razor rendering engine

aspx using WebForm engine

Different syntax

The two files are inserted into the ASP tag in a different way, the former is more straightforward than the latter. If you develop in the previous way, you can no longer drag and drop various server segment controls. Other don't know, my web development experience is very few, I know how many, the former is the way Microsoft recommended

The difference between Razor and aspx

Razor

Aspx

@{int a = 123;  String b = "Demoshop"; }
<% int a = 123; String b = "Demoshop";%>
<div> @Model .content</div>
<div> <%:model.content%></div>
<div> @Html. Raw (model.content) </div>
<%foreach (var item in collection) {%> <span><%:item. Key%></span><%}%>
@foreach (var item in collection) {@: I am a pure text @item. Value}
<%foreach (var item in collection) {%> I am the pure text <%:item. Key%><%}%>
@for (int i = 0; i < 3; i++) {@: currently @i. }
<%for (int i = 0; i < 3; i++) {%> is now <%=i%>.<%}%>
@ (Model.content = = ""? ") No ": model.content)
<%:model.content== ""? " No ": model.content%>
@* Annotations *@
<%--Annotations--%>

(ii) commonly used places

[Email protected] Escape
Wording: @@
Example:[email protected]@163.com

[Email protected] Comments
Wording: @**@

3. Take request
For example: @Request. Url

[Email protected]@ scopes and HTML mixed use
The scope uses the {} description, and the HTML can be output directly within the scope.
Example: @{
Define Variable i
int i = 1;
<em>12</em>
<br/>
}

5. Output content in the @ scope
notation: @:
For example:
@{
int j = 1;
@:d IV Direct output content <br/>
@:<br/>
<div>@j=6</div>
@j
<br/>
}

6. Output HTML method in the @ Scope 1
Use string to describe output
For example:
@{
String html = "<b>wo shi html</b>";
@html

7. Output HTML method in the @ Scope 2
Using HtmlHelper output
For example:
@{
@Html. Raw (Html)

8. Output HTML method in the @ Scope 3
Using the Htmlstring class output
For example:
@{
var html2 = new Htmlstring ("<b>wo shi html</b>");
@html2

9. Output HTML method in the @ Scope 4
Using the Mvchtmlstring class output
For example:
@{
var html3 = mvchtmlstring.create ("<b>wo shi html</b>");
@html3

10. Dealing with generics <> conflict issues
We can use () to enclose the statement.
For example:
@ (list. Tolist<char> ());

[Email protected] data type conversion
Using the Asdecimal () method to convert
For example:
@ ("123". Asdecimal () +1)

[Email protected] Number type judgment
Using the Isint () method
For example:
@ ("123". Isint ()? " is ":" No ");

[email protected] type conversion
Using the Asbool () method to convert
For example:
@ ("true".) Asbool ())

[email protected] type judgment
Use the Isbool () method to determine
For example:
@ ("True".) Isbool ()? " Yes ":" No ")

15. Date Type conversions
Using the Asdatetime () method to convert
For example:
@ ("2011/4/11".) Asdatetime (). Tolongdatestring ())

16. Path Conversion
Use the href () method to convert
For example:
@Href ("~/")

See here, I think if it is not applicable to the scope of ASPX relatively large, it is still razor syntax is more concise, decided to use razor

The former should be the latter update, and I have seen similar updates in MyBatis

The difference should be just that.

The difference between ASPX and razor

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.