Without the @
, the razor engine interprets speaker.Name;
as pure C#—that is, simply referencing a property, but not doing anything with it—but that won't compile. A statement which simply references a property by itself, without getting or setting its value, is not valid in C#.
Consider this razor
@foreach (var speaker in Model)
{
var name = speaker.Name;
@name
}
The first line is pure C#. It declares a variable, name
and initializes it with the value of speaker.Name
.
The second line is interpreted as a razor print directive, which prints the value of name
in the output.