Reputation: 1950
is it possible to do something like the following in ASP.NET:
<tr<%= index++ % 2 == 0 ? " class=\"alt-row\"" : ""; %>>
in other words, is there a way to escape the angle brackets for the inline code block or something?
(i know the alternative is:
<% if (index++ % 2 == 0) { %>
<tr class="alt-row">
<% } else { %>
<tr>
<% } %>
. i'm just curious if the other way is possible)
Upvotes: 0
Views: 918
Reputation: 126577
Yes, you can do this (at least, in MVC), though your example has a couple errors.
Here's a fixed version:
<tr<%= index++ % 2 == 0 ? " class=\"alt-row\"" : "" %>>
Upvotes: 5
Reputation: 43094
I've used the <% %> construct inside tags to assign properties so I would imagine this would work. Did it not work?
Upvotes: 0
Reputation: 351566
Have you tried it yet? A similar test worked just fine for me.
Upvotes: 0