Ben Strombeck
Ben Strombeck

Reputation: 1549

What does the "@" in ASP MVC mean/do?

I know this is a simple question, but I am new to ASP MVC and just can't find the answer to this anywhere - what is the "@" that I am seeing everywhere? example:

@{
    ViewBag.Title = "Welcome";
}

<h2>Welcome</h2>

<ul> 
   @for (int i=0; i < ViewBag.NumTimes; i++) { 
      <li>@ViewBag.Message</li> 
   } 
</ul>

Upvotes: 4

Views: 3619

Answers (3)

D-loader
D-loader

Reputation: 51

It's the symbol that "toggles" between code and HTML so to speak. For Webforms, the <% %> syntax is used. Whenever the server encounters the symbol, it will execute the code (C# in your case), and replace it with HTML. If you've ever used PHP it's equal to the

 <?php ?> 

tag.

Upvotes: 3

xwrs
xwrs

Reputation: 1297

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

ViewBag properties are dynamic and can be populated from controller.

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

Upvotes: 4

David M
David M

Reputation: 72930

This is part of the syntax for the Razor view engine. You should find answers by including this in your search terms. From the Razor page on MSDN:

‘@’ is the magic character that precedes code instructions

Upvotes: 2

Related Questions