Reputation: 6741
I need to split a comma separated string and build a <ul>
.
I cannot seem to find the sweet spot.
Here is my code:
<ul>
@{
string[] ps = Model.ProductsServices.Split(',');
for (byte i = 0; i < ps.Length; i++)
{
<li>ps[i]</li>
}
}
</ul>
Here is the result of the above code.
Upvotes: 0
Views: 5404
Reputation: 50149
Try putting an @
in from of ps[i]
.
<ul>
@{
string[] ps = Model.ProductsServices.Split(',');
for (byte i = 0; i < ps.Length; i++)
{
<li>@ps[i]</li>
}
}
</ul>
Also there is little reason to use a plain for
loop, a foreach
is more readable and just as performant.
var ps = Model.ProductsServices.Split(',');
foreach (string service in ps)
{
<li>@service</li>
}
Upvotes: 5