Switch statement in a CSHTML Razor page

Your switch needs to be completely enclosed in a block and it needs to be “broken” properly:

// Use the @{ } block and put all of your code in it
case "test":
// Use the text block below to separate html elements from code

Test Site</h1>
break; // Always break each case
case "prod":

Prod Site</h1>

WTF Site</h1>

Because the 

 tags are enclosed html blocks by themselves, you may not need the blocks for separation. It's just my habit to include them.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s