?
Solved

What is the meaning of [ ] in Razor?

Posted on 2011-10-20
4
Medium Priority
?
712 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:newbieweb
  • 2
  • 2
4 Comments
 
LVL 9

Assisted Solution

by:gery128
gery128 earned 2000 total points
ID: 37004893
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
 

Author Comment

by:newbieweb
ID: 37009944
Ok, then wahat is the meaning of:

@:[
0
 
LVL 9

Accepted Solution

by:
gery128 earned 2000 total points
ID: 37011604
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
 

Author Closing Comment

by:newbieweb
ID: 37011664
Thanks!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question