What does "@" mean in ASP MVC?

I know this is a simple question, but I'm new to ASP MVC and just can't find the answer to it anywhere - what is @ that I see everywhere? Example:

@{ ViewBag.Title = "Welcome"; } <h2>Welcome</h2> <ul> @for (int i=0; i < ViewBag.NumTimes; i++) { <li>@ViewBag.Message</li> } </ul> 
+4
source share
3 answers

@ is the syntax element of the Razor engine, which is used in ASP.NET MVC 3. Your code will display text from ViewBag.Message ViewBag.NumTimes times.

ViewBag properties are dynamic and can be populated from the controller.

Take a look at http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx for Razor syntax

+4
source

This is a character that "switches" between code and HTML, so to speak. For Web forms, the syntax is <%%>. Whenever the server encounters a character, it executes the code (C # in your case) and replaces it with HTML. If you have ever used PHP, it was equal

  <?php ?> 

tag.

+3
source

This is part of the syntax of the Razor viewer. You must find the answers by including this in your search terms. On the Razor page on MSDN :

'@ is a magic character preceding code instructions

+2
source

All Articles