c# - Elegant MVC code for optional surrounding tag -


what more elegant code accomplish following:

foreach(var filter in model.filters) {   if(filter.selected)   {     <div class="crumb crumb_selected" id="@filter.id">       @* more html can here *@       @filter.title       <span class="counter">         (@filter.count)       </span>     </div>   } else {     <div class="crumb" id="@filter.id">       <a href="@model.clickurl(model.selectedfilters, filter)">       @* more html can here similar code above *@         @filter.title         <span class="counter">           (@filter.count)         </span>       </a>     </div>   } } 
  • the repeated html code div / span seems bad code
  • also css-class specification should solved in elegant version

@helper myhelper(somedatatype filter) {   @* more html can here *@   @filter.title   <span class="counter">     (@filter.count)   </span> }  foreach(var filter in model.filters) {   if (filter.selected)   {     <div class="crumb crumb_selected" id="@filter.id">       @myhelper(filter)     </div>   } else {     <div class="crumb" id="@filter.id">       <a href="@model.clickurl(model.selectedfilters, filter)">         @myhelper(filter)       </a>     </div>   } } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -