What pros(positive sides) of using Spark view engine for ASP.NET MVC project. Why it better then default view engine?
+22
A:
One important thing about Spark View engine is that its syntax is very similar to HTML syntax, that way your views will be clean and you will avoid "tag soup" that is in WebForms View engine. here is an example:
Spark:
<viewdata products="IEnumerable[[Product]]"/>
<ul if="products.Any()">
<li each="var p in products">${p.Name}</li>
</ul>
<else>
<p>No products available</p>
</else>
WebForms:
<%var products = (IEnumerable<Product>)ViewData["products"] %>
<% if (products.Any()) %>
<ul>
<% foreach (var p in products) { %>
<li><%=p.Name %></li>
</ul>
<%} } %>
<% else { %>
<p>No products available</p>
<% }%>
Marwan Aouida
2009-05-12 14:35:30
WOW, that is pretty
Dinah
2009-10-15 19:04:51
Can u add some more examples?
Quintin Par
2010-01-19 18:26:30
@Quintin-Par you can find more examples on the official website:http://sparkviewengine.com/documentation/expressions
Marwan Aouida
2010-01-19 21:07:18
While that WebForms code could be made cleaner (see Razzie's answer), what's especially enlightening is that it's hard to spot the compilation and logic errors. The output, after adding a missing semicolon, will give you a `</ul>` for every product. Spark makes it easier to fall into the pit of success.
Thomas G. Mayfield
2010-01-25 15:46:59
+8
A:
It avoids the HTML tag soup you see a lot. Consider Spark:
<ul>
<li each='var p in ViewData.Model.Products'>
${p.Name}
</li>
</ul>
as opposed to the classic html tag soup variant:
<ul>
<% foreach(var p in ViewData.Model.Products) { %>
<li>
<%= p.Name %>
</li>
<% } %>
</ul>
The Spark syntax is much cleaner.
Razzie
2009-05-12 14:35:57