Reputation: 61479
In a loop I need to wrap div
s after first one into mechanism that hides them and shows when expanded, easy right.
//above this lives code that draws a product section
if (product.DisplayOrder == 1 && Model.Count > 1)
{
<div class="arrow-with-text" style="cursor: pointer;">
<div class="arrow-right"></div>
<div class="arrow-down" style="display: none"></div>
<div style="margin-left: 2em;margin-top: -1.3em;font-size: 1.2em;color: #2280c4;">Other available Wills…</div>
</div>
<div class="other-wills" style="display: none">
}
else (product.DisplayOrder == Model.Count)
{
</div>
}
What I expected was all sections that go after first being wrapped in other-wills
div and then being closed on last one. What it actually get's rendered to is this.
<div class="arrow-with-text" style="cursor: pointer;">
<div class="arrow-right"></div>
<div class="arrow-down" style="display: none"></div>
<div style="margin-left: 2em;margin-top: -1.3em;font-size: 1.2em;color: #2280c4;">Other available Wills…</div>
</div>
<div class="other-wills" style="display: none">
}
else (product.DisplayOrder == Model.Count)
{
</div>
<div class="sections-wrapper">
which isn't exactly what I expected (it reendered }else product.DisplayOrder == Model.Count){
as text).
How do I make razor interpret my closing of if
statement and else
correctly?
Upvotes: 0
Views: 129
Reputation: 5252
Use
@Html.Raw("</div>")
and
@Html.Raw("<div class=\"your-class\">")
for the 'stray' dynamic divs
Upvotes: 1