@ And & lt; % & gt; in ASP. Net MVC, and in asp. netmvc

Source: Internet
Author: User
Tags actionlink

@ And <%> in ASP. Net MVC, and in asp. netmvc

When I first came into contact with MVC, I believe many people have learned <%> first, and then suddenly met @ one day, and then I was overwhelmed ~

Today, one of my friends asked me why he downloaded an MVC Demo online and the view page <%> does not work, and it is a one-page @?

I once had such questions.

Vs mvc has two view engines: ASPX (C #) and Razor (cshtml)

We recommend that you use the Razor view engine later. (Razor engine is already used by default in VS2017)

<%> Is the identifier of the C # code inserted in the ASPX engine view page. In Razor, the simpler @ is used instead.

This is a powerful improvement:

1. @ I => <%: I %>

2. Model: @ Model RazorDemo. Models. Customer

3. Code introduction:

1 <div> 2 // ASPX: 3 <% for (int I = 0; I <10; I ++) {%> 4 5 <span> <% = I %> </span> 6 <% }%> 7 8 // Razor: 9 @ for (var I = 0; I <10; I ++) 10 {11 <span> @ I </span> 12 I ++; 13 <p> @ I </p> 14 int B = I + 10; 15 <div> 16 int c = I ++; 17 </div> 18} 19 20 @ {21 int demo = @ Model. age; 22 <p> sssss </p> demo ++; // with the Razor engine, it is very easy to mix Html and C # code? 23 demo = 10 + 10; 24 int demo2 = 3; 25} 26 </div>

Have you found any advantages and progress?

Learning programming is inseparable from talking to instances.

Let's look at another piece of code:

Razor engine:

1 @ model _ 20170913. Models. Person // strong type Model definition 2 3 @ {4 Layout = null; 5} 6 7 <! DOCTYPE html> 8 9 

ASPX engine:

1 <% @ Page Language = "C #" Inherits = "System. Web. Mvc. ViewPage <MvcStudyDemo. singerlist>" %> // strong type Model definition 2 3 <! DOCTYPE html> 4 5 

At this point, I believe the reader should have a basic understanding of @ in Razor and <%> In ASPX.

When the ASPX engine is used to develop the MVC project, the Razor engine is ready.

Come on ~~!

Related Article

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.