@ 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 ~~!