In MVC view I have a 'for' command that in each value I want to write specified tag.
I show you a simple case here:
@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 use MVC4 Razor view.
Thanks for your time in advance.
In C#, Switch statement is a multiway branch statement. It provides an efficient way to transfer the execution to different parts of a code based on the value of the expression. The switch expression is of integer type such as int, char, byte, or short, or of an enumeration type, or of string type.
No, you cannot do something like case val_1 && val_2 . case statements only accept a single value.
A switch statement using multiple value cases correspond to using more than one value in a single case. This is achieved by separating the multiple values in the case with a comma. Example 1: Go.
It's simple, you use your code same as this, It's works fine.
@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>
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With