如何通过打开和关闭标签禁用Razor聪明?

时间:2015-08-03 11:36:07

标签: asp.net-mvc razor

在一个循环中,我需要在第一个之后将div包装成隐藏它们的机制,并在展开时显示,这很容易。

//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>
                }

我所期望的是首先被包裹在other-wills div中然后在最后一个被关闭的所有部分。实际得到的是这个。

                        <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">

这与我的预期完全不同(它将}else product.DisplayOrder == Model.Count){作为文本重新发送。)

enter image description here

如何让剃刀正确解释if语句和else的正确结束?

1 个答案:

答案 0 :(得分:1)

使用

@Html.Raw("</div>")

@Html.Raw("<div class=\"your-class\">")

用于'stray'动态divs