What is the meaning of [ ] in Razor?

The default MVC3 web application has the following:

@if(Request.IsAuthenticated) {
    <text>Welcome <b>@Context.User.Identity.Name</b>!
    [ @Html.ActionLink("Log Off", "LogOff", "Account") ]</text>
}
else {
    @:[ @Html.ActionLink("Log On", "LogOn", "Account") ]
}


What does this do:
 [ @Html.ActionLink("Log Off", "LogOff", "Account") ]

then a second time with the @ outside the square brackets:
 @:[ @Html.ActionLink("Log On", "LogOn", "Account") ]

Thanks.
newbiewebSr. Software EngineerAsked:
Who is Participating?
 
gery128Commented:
As you have  "@if(" in first code block, you don't require @: in this line:

[ @Html.ActionLink("Log Off", "LogOff", "Account") ]

while, [ @Html.ActionLink("Log On", "LogOn", "Account") ] line requires it as you are specifying this Code Nuggets within the static content.

@: is used to define start of static content.

In @: [,  [ is only static content. rendered as [ only.

refer this for razor syntax introduction.
http://weblogs.asp.net/scottgu/archive/2010/12/15/asp-net-mvc-3-razor-s-and-lt-text-gt-syntax.aspx
0
 
gery128Commented:
The square brackets would be rendered as it is.
like this:
Welcome (userName here)!  [Log Off]            ---for authenticated user.
[Log On]                                                         ---for unauthenticated user.
0
 
newbiewebSr. Software EngineerAuthor Commented:
Ok, then wahat is the meaning of:

@:[
0
 
newbiewebSr. Software EngineerAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.