Reputation: 1549
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
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
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
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