您好我在剃刀中有以下代码:
@{
foreach (var item in this.Model)
{
if (item.Items == null)
{
@: <li @{if (item.Active) { <text> class="active" </text> } }>
if (item.SpanClass == null)
{
@: <a href="@item.Url" @{ if (item.Active) { <text> class="waves-effect active" </text> } else { <text> class="waves-effect" </text> } }><i class="@item.Icon"></i><span> @item.Text </span></a>
}else
{
@: <a href="@item.Url" @{ if (item.Active) { <text> class="waves-effect active" </text> } else { <text> class="waves-effect" </text> } }><i class="@item.Icon"></i><span> @item.Text <span class="@item.SpanClass">@item.SpanValue</span></span></a>
}
}
@: </li>
}
}
看起来像这样:
但我去了:
然后代码格式被破坏:
有任何线索吗?
答案 0 :(得分:0)
我会做那样的事情
@{
foreach (var item in this.Model)
{
var activeClass = item.Active ? "active" : "";
if (item.Items == null)
{
<li class="@activeClass">
@if (item.SpanClass == null)
{
<a href="@item.Url" class="waves-effect @activeClass"><i class="@item.Icon"></i><span> @item.Text </span></a>
}
else
{
<a href="@item.Url" class="waves-effect @activeClass"><i class="@item.Icon"></i><span> @item.Text <span class="@item.SpanClass">@item.SpanValue</span></span></a>
}
</li>
}
}
}