ASP.NET MVC Spark view engine
Asked Answered
I

3

13

What pros(positive sides) of using Spark view engine for ASP.NET MVC project. Why it better then default view engine?

Indigotin answered 12/5, 2009 at 14:22 Comment(0)
O
24

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>
<% }%>
Oldfangled answered 12/5, 2009 at 14:35 Comment(3)
Can u add some more examples?Infiltrate
@Quintin-Par you can find more examples on the official website:sparkviewengine.com/documentation/expressionsOldfangled
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
B
8

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.

Bobbi answered 12/5, 2009 at 14:35 Comment(0)
T
0

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...

Tosha answered 17/9, 2011 at 20:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.