And the following will be output onto the page, seemingly looking just like the rest of the HTML plain text on it:Today is: @DateTime.Now
Today is: 7/8/2014 4:56:04 PM
You can see how it combines HTML div tags with some .NET properties (DateTime.Now). Razor uses pieces of both to simplify tasks and shoot an output to the browser for users. The syntax can vary sometimes from both, but tends to be shorter and simpler. Overall, the goal is to render HTML and make life easier for the web developer.
In Razor, the expression begins right after the @ symbol and ends at the closing bracket.
As a sample:If/else statement using Web Forms syntax:
<% if(User.IsAuthenticated) { %> Hello, <%: User.Username %>! <% } %> <% else { %> Please <%: Html.ActionLink("Login") %> <% } %>Razor syntax:
@if(User.IsAuthenticated) { Hello, @User.Username! } else { Please @Html.ActionLink("Login") }Though they use a different syntax, both render the same HTML to the browser! Source: WPF 4.5 Unleashed