Use switch housing in MVC mode

In the MVC view, I have a 'for' command, which in each value I want to write the specified tag.

I will show you a simple example:

@for (var i = 0; i < 4; i++) { <div> @(switch (i) { case 0: ??? //write "<div>Custom Value 1</div>" break; case 1: ??? //write "<span>Custom Value 2</span>" break; }) </div> } 

I am using the MVC4 Razor view.

Thanks for your time in advance.

+6
source share
3 answers

It's simple, you use your code just like this one, it works great.

 @for (var i = 0; i < 4; i++) { <div> @switch (i) { case 0: <div>Custom Value 1</div> break; case 1: <span>Custom Value 2</span> break; } </div> } 
+10
source

That should work.

 @for (var i = 0; i < 4; i++) { <div> @switch (i) { case 0: <div>Custom Value 1</div> break; case 1: <span>Custom Value 2</span> break; } </div> } 
+1
source
 Switch (condition) { Case value or result : Statement Break; Default: } 
+1
source

All Articles