简体   繁体   中英

How can I declare local variable in Razor vb.net?

it seems easy but I can't get it to work. I am trying to declare a variable using vb.net in my layout.

I tried

@Dim lst As New List(Of String)

and also

@{Dim lst As New List(Of String)}

like I have seen in an other SO question but for C# and MVC3.

I hear for VB you have to use @Code...End Code blocks, like so:

<!-- Declare variable  -->
@Code  Dim mood = "saucy"  End Code

<!-- Using the variable -->
<p>Today I am feeling: @mood</p>        

<!-- Multi-statement block -->    
@Code 
    Dim greeting = "Welcome to our site!"
    Dim weekDay = DateTime.Now.DayOfWeek
    Dim greetingMessage = greeting & " Today is: " & weekDay.ToString()
End Code 
<p>The greeting is: @greetingMessage</p>

Example shamelessly ripped from: http://www.asp.net/web-pages/overview/getting-started/introducing-razor-syntax-vb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM