I have some MVC2 code that loops a collection of type Product held within the view model. Each time I want to output the data I have to use <%: %> along with using <% %>, for example:
<% foreach (Product item in Model.ProductsCollection) {
if (item.doesExist == true) { %>
<%: item.name %>
<% } %>
Is there any way to still output item.name without having to close & open tags, e.g. in classic asp we used response.write()?
I appreciate the need to encode data using <%: %>, and am not wanting to bypass this, just wanting to output the encoded data without needing the bracket overhead.
Thanks
You can use
Response.Write()in conjunction withHtml.Encode()