I'm trying to find out how I can put a condition within my loop as I print out list items...
<ul>
<% foreach (var filter in Model.Filter)
{ %>
<li <% filter.TagChecked == 1 ? //yes : //no %>><%: filter.TagLabel %> <span class="closeImage"><img src="/Content/Images/filterButtonClose.gif" /></span></li>
<% } %开发者_开发知识库>
</ul>
I'm trying to see if a filter is checked... if yes, then I need to write the class and also add the image. If not, then just write a normal li
<ul>
<% foreach (var filter in Model.Filter)
{ %>
<li <%: filter.TagChecked == 1 ? "class=\"some-class\"" : "" %>><%: filter.TagLabel %> <span class="closeImage"><img src="/Content/Images/filterButtonClose.gif" /></span></li>
<% } %>
</ul>
Just return the needed string:
<%: filter.TagChecked == 1 ? " class=\"myclass\"" : string.Empty %>
精彩评论