完成以下任务的更优雅的代码是什么:
foreach(var filter in Model.Filters)
{
if(filter.Selected)
{
<div class="crumb crumb_selected" id="@filter.ID">
@* much more html can be here *@
@filter.Title
<span class="counter">
(@filter.Count)
</span>
</div>
} else {
<div class="crumb" id="@filter.ID">
<a href="@Model.ClickUrl(Model.SelectedFilters, filter)">
@* much more html can be here but similar code as above *@
@filter.Title
<span class="counter">
(@filter.Count)
</span>
</a>
</div>
}
}
- div / span 的重复 html 代码似乎是错误的代码
- css-class规范也应该在优雅的版本中解决