@{
switch(x)
{
case 1:
// Do something
break;
case 2:
// Do something
break;
default:
// Do something
break;
}
}
The default statement in the switch acts the same as your intended behaviour for else. Try giving it a shot as it's probably better practice than multiple else if's.
I found a solution to this problem if anyone is interested :-)
<h2>PAGE</h2>
@{
var years = Umbraco.Content(3772).Children;
for (int i = 0; i < years.Count(); i++) {
var page = years[i];
if (i < 3) {
<a class="btn btn-primary" href="@page.Url">@page.Name</a>
} else if (i == 3) {
@:<label id="lblSelect">
@:<select id="selectPointOfInterest" title="Vælg årstal" onchange="location = this.value;">
<option value="@page.Url">@page.Name</option>
} else if (i < years.Count() && i > 3) {
<option value="@page.Url">@page.Name</option>
} else if (i == years.Count()-1) {
<option value="@page.Url">@page.Name</option>
@:</select>
@:</label>
}
}
}
Multiple Else if inside if statement. Umbraco Code interpretation
Hey guys, How would one write this correctly?
The last else if and the else will not be interpreted as code and I cant figure where to place the extra @ tag. Can anyone help me?
Full code is:
Hi Nicolai,
When you have multiple
else if
statements it's sometimes better to use aswitch
https://msdn.microsoft.com/en-us/library/06tc147t.aspxYou code may look something like the following:
The default statement in the switch acts the same as your intended behaviour for
else
. Try giving it a shot as it's probably better practice than multipleelse if
's.Gary
Hi Gary,
Thanks for trying to help! Im afraid I cant use switch case statements in this particularly situation because I need the logical operations.
I have added the full code example to my main post.
Regards, Nicolai
The problem with the example is opening some html tags withouth closing them in the same branch of the IF.
Try generating a string of your html and then printing it out
I found a solution to this problem if anyone is interested :-)
is working on a reply...