Let's say I am working in a .aspx page (or View, for the MVC folk) and I have a block of inline code:
<p>Some HTML and content</p>
<% foreach (var x in foo) { %>
<%= x.myProperty %>
<% } %>
<p>Moar HTMLz</p>
Is there a more efficient, less cumbersome way to extract text into the markup than this model? It seems like there are a lot of <%
's
EDIT I guess what I'm really asking is if there's any better way to get text on the page from a codeblock without leaving the code block, re-entering into a code block, and then reentering the enclosing codeblock.
If the goal is strictly to have fewer <% %> sections, you can write it out the long way, but that's hardly an improvement:
If you just want to keep it out of the aspx page, you could move it to a control:
One advantage of this technique is that you could utilize a different view engine (say, NHaml) for the partial while still keeping the general structure of your aspx page (view) in tact.