开发者

Code block in View not able to access base View Properties

I've created a Base View in my project to hold the basic properties that can be accessed anywhere in any of the views. The BaseView class contains the following properties. WebSession, WebRequest, WebMain, etc.

When I try to access the properties from within the views, they are ac开发者_高级运维cessible. But, I had a requirement when I had to set some global variable on the top of the view. So I created those variables in a separate code block on top of the view. Here is the code...

@(
    Dim panelInfoVisibility As Boolean = False
    Select Case WebSession.Menu
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Home
            panelInfoVisibility = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Reservieren
            panelInfoVisibility = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Kaufen
            panelInfoVisibility = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Verkaufen
            panelInfoVisibility = True
        Case arwedes.WebShop.Web.Navigation.MenuEnum.Member
            If Request.RawUrl.Contains("login") Then
                panelInfoVisibility = True
            End If
    End Select
)

This code gives compilation errors when compiled that 'WebSession' is not declared. It may be inaccessible due to its protection level.

while in the view below I am using this variable like this...

@If panelInfoVisibility Then
    @: <div id="panelInfo">Here it goes....</div>
End If

Can anybody tell me what I am doing wrong here...


The issue most likely is related to the fact that FormContext does not exist in your BaseView layout file when it is being processed. It is not clear from your question how your BaseView class is derived, but instantiating a FormContext is a good place to start. Add the following at the top of your BaseView:

Me.ViewContext.FormContext = New FormContext()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜