1

我想知道为什么如下:

             @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>
             @}

抛出以下错误:

说明:在编译服务此请求所需的资源期间发生错误。请查看以下特定错误详细信息并适当修改您的源代码。

编译器错误消息:CS1501:方法 'Write' 没有重载需要 0 个参数

else if这个错误是在我的块上抛出的。我是 ASP.net 和 razor 的新手,但据我了解,我所做的是正确的,不是吗?因为它们都是布尔返回。

4

2 回答 2

1

您的剃刀语法错误。您应该用 the 包围整个 if/else if 块,@{}并从 if/else 分支的各个右大括号中删除 @ 符号。

@{
    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>
    }
}
于 2013-04-11T15:49:57.987 回答
1

我认为您不需要 else if 中的“@”。

试试这样:

        @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>
        }
于 2013-04-11T15:53:34.733 回答