MVC视图中的全局代码段发出错误....“表达式预期。”

时间:2011-09-06 21:20:58

标签: asp.net asp.net-mvc vb.net asp.net-mvc-3 razor

我有一个视图,其中我有一个代码块,我在其中设置一些变量,然后使用这些变量来显示或隐藏某些区域......

当我建立这个网站时。在@(Syntax Error和另一个Expression Expected上出现编译错误。任何人都可以指导我在这里做错了什么....

@ModelType arwedes.WebShop.Model.Gruppe1Liste
@Code

End Code
@(
    Dim lblInfoTitleText As String = String.Empty
    Dim lblInfoText As String = String.Empty
    Dim panelInfoVisibility As Boolean = False
    Select Case WebSession.Menu
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Home
            lblInfoTitleText = arwedes.WebShop.Model.Text.GetText("Info.HomeTitle", AppSession.Language)
            lblInfoText = arwedes.WebShop.Model.Text.GetText("Info.Home", AppSession.Language)
            panelInfoVisibility = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Reservieren
            lblInfoTitleText = arwedes.WebShop.Model.Text.GetText("Info.ReservierenTitle", AppSession.Language)
            lblInfoText = arwedes.WebShop.Model.Text.GetText("Info.Reservieren", AppSession.Language)
            panelInfoVisibility = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Kaufen
            lblInfoTitleText = arwedes.WebShop.Model.Text.GetText("Info.KaufenTitle", AppSession.Language)
            lblInfoText = arwedes.WebShop.Model.Text.GetText("Info.Kaufen", AppSession.Language)
            panelInfoVisibility = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Verkaufen
            lblInfoTitleText = arwedes.WebShop.Model.Text.GetText("Info.VerkaufenTitle", AppSession.Language)
            lblInfoText = arwedes.WebShop.Model.Text.GetText("Info.Verkaufen", AppSession.Language)
            panelInfoVisibility = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Member
            If Request.RawUrl.Contains("login") Then
                lblInfoTitleText = arwedes.WebShop.Model.Text.GetText("Info.MemberTitle", AppSession.Language)
                lblInfoText = arwedes.WebShop.Model.Text.GetText("Info.Member", AppSession.Language)
                panelInfoVisibility = True
            End If
    End Select

    Dim bShowCatMenu As Boolean = False
    Select Case WebSession.Menu
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Home
            bShowCatMenu = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Kaufen
            bShowCatMenu = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Reservieren
            bShowCatMenu = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Member
            If Request.ServerVariables("SCRIPT_NAME") = "/membermenu.aspx" Or Request.ServerVariables("SCRIPT_NAME") = "/welcome.aspx" Then
                bShowCatMenu = True
            End If
    End Select
)
@If panelInfoVisibility Then
    @: <div id="panelInfo">
    @: <p style="text-align: center; font-size: 8pt"> <b> <span id="lblInfoTitle">@lblInfoTitleText</span>
    @: </b><br /> <span id="lblInfo">@lblInfoText</span> </p> </div> 
End If

2 个答案:

答案 0 :(得分:1)

而不是@( ...)将您的代码放在@Code ... End Code块中。

答案 1 :(得分:0)

试试这样:

@ModelType arwedes.WebShop.Model.Gruppe1Liste
@Code
    Dim lblInfoTitleText As String = String.Empty
    Dim lblInfoText As String = String.Empty
    Dim panelInfoVisibility As Boolean = False
    Select Case WebSession.Menu
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Home
            lblInfoTitleText = arwedes.WebShop.Model.Text.GetText("Info.HomeTitle", AppSession.Language)
            lblInfoText = arwedes.WebShop.Model.Text.GetText("Info.Home", AppSession.Language)
            panelInfoVisibility = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Reservieren
            lblInfoTitleText = arwedes.WebShop.Model.Text.GetText("Info.ReservierenTitle", AppSession.Language)
            lblInfoText = arwedes.WebShop.Model.Text.GetText("Info.Reservieren", AppSession.Language)
            panelInfoVisibility = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Kaufen
            lblInfoTitleText = arwedes.WebShop.Model.Text.GetText("Info.KaufenTitle", AppSession.Language)
            lblInfoText = arwedes.WebShop.Model.Text.GetText("Info.Kaufen", AppSession.Language)
            panelInfoVisibility = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Verkaufen
            lblInfoTitleText = arwedes.WebShop.Model.Text.GetText("Info.VerkaufenTitle", AppSession.Language)
            lblInfoText = arwedes.WebShop.Model.Text.GetText("Info.Verkaufen", AppSession.Language)
            panelInfoVisibility = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Member
            If Request.RawUrl.Contains("login") Then
                lblInfoTitleText = arwedes.WebShop.Model.Text.GetText("Info.MemberTitle", AppSession.Language)
                lblInfoText = arwedes.WebShop.Model.Text.GetText("Info.Member", AppSession.Language)
                panelInfoVisibility = True
            End If
    End Select

    Dim bShowCatMenu As Boolean = False
    Select Case WebSession.Menu
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Home
            bShowCatMenu = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Kaufen
            bShowCatMenu = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Reservieren
            bShowCatMenu = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Member
            If Request.ServerVariables("SCRIPT_NAME") = "/membermenu.aspx" Or Request.ServerVariables("SCRIPT_NAME") = "/welcome.aspx" Then
                bShowCatMenu = True
            End If
    End Select
End Code
@If panelInfoVisibility Then
    @: <div id="panelInfo">
    @: <p style="text-align: center; font-size: 8pt"> <b> <span id="lblInfoTitle">@lblInfoTitleText</span>
    @: </b><br /> <span id="lblInfo">@lblInfoText</span> </p> </div> 
End If

这就是说,你编写的代码不属于视图。那么问题的真正解决方案是外化它(帮助者,视图模型?)。

您能想象给网页设计师提供意见吗?他将绝望地尖叫。