What pros(positive sides) of using Spark view engine for ASP.NET MVC project. Why it better then default view engine?
ASP.NET MVC Spark view engine
Asked Answered
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>
<% }%>
Can u add some more examples? –
Infiltrate
@Quintin-Par you can find more examples on the official website:sparkviewengine.com/documentation/expressions –
Oldfangled
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. –
Clitoris 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.
I really like the Bindings features.
http://sparkviewengine.com/documentation/bindings
You can specify something in the bindings and use nice xml markup for it in your views.
We have bindings for all the html helpers we use in our views eg.
<textbox for=""/>
<dropdown for="" items=""/>
etc etc...
© 2022 - 2024 — McMap. All rights reserved.