1

I am wondering why the following:

             @if(Request.LogonUserIdentity.IsAnonymous){
                <ul id="menu">
                    <li>@Html.ActionLink("Location", "Index", "Location")</li>
                    <li>@Html.ActionLink("Map", "Map", "Home")</li>
                    <li>@Html.ActionLink("Help", "Help", "Home")</li>
                </ul>
             @}else if(Request.LogonUserIdentity.IsAuthenticated){
                <ul id="menu">
                    <li>@Html.ActionLink("Location", "Index", "Location")</li>
                    <li>@Html.ActionLink("Service", "Index", "Service")</li>
                    <li>@Html.ActionLink("Service Assignment", "Index", "ServiceAssignment")</li>
                    <li>@Html.ActionLink("Content Management", "Index", "Content")</li>
                </ul>
             @}

Is throwing the following error:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1501: No overload for method 'Write' takes 0 arguments

This error is thrown on my else if block. I am new to ASP.net and razor, but from my understanding what I did is correct no? Since they both are Boolean returns.

2 Answers 2

1

I think you don't need the "@" in the else if.

Try like this:

        @if(Request.LogonUserIdentity.IsAnonymous){
           <ul id="menu">
                <li>@Html.ActionLink("Location", "Index", "Location")</li>
                <li>@Html.ActionLink("Map", "Map", "Home")</li>
                <li>@Html.ActionLink("Help", "Help", "Home")</li>
            </ul>
        }else if(Request.LogonUserIdentity.IsAuthenticated){
           <ul id="menu">
                <li>@Html.ActionLink("Location", "Index", "Location")</li>
                <li>@Html.ActionLink("Service", "Index", "Service")</li>
                <li>@Html.ActionLink("Service Assignment", "Index", "ServiceAssignment")</li>
                <li>@Html.ActionLink("Content Management", "Index", "Content")</li>
            </ul>
        }
Sign up to request clarification or add additional context in comments.

Comments

1

Your razor syntax is goofed. You should surround the entire if/else if block with the @{} and remove the @ symbol from the various closing braces in your if/else branch.

@{
    if (Request.LogonUserIdentity.IsAnonymous)
    {
        <ul id="menu">
            <li>@Html.ActionLink("Location", "Index", "Location")</li>
            <li>@Html.ActionLink("Map", "Map", "Home")</li>
            <li>@Html.ActionLink("Help", "Help", "Home")</li>
        </ul>
    }
    else if (Request.LogonUserIdentity.IsAuthenticated)
    {
        <ul id="menu">
            <li>@Html.ActionLink("Location", "Index", "Location")</li>
            <li>@Html.ActionLink("Service", "Index", "Service")</li>
            <li>@Html.ActionLink("Service Assignment", "Index", "ServiceAssignment")</li>
            <li>@Html.ActionLink("Content Management", "Index", "Content")</li>
        </ul>
    }
}

2 Comments

Or just use @if. Since the HTML tags within each block are valid, Razor can figure out that the else if and closing bracket are code.
@JasonBerkan - good point. I think that these two methods are just style choices at that point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.