ASP.NET MVC Spark 视图引擎

发布于 2024-07-20 12:21:47 字数 66 浏览 2 评论 0原文

在 ASP.NET MVC 项目中使用 Spark 视图引擎有什么优点(积极的方面)。 为什么它比默认视图引擎更好?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眉黛浅 2024-07-27 12:21:47

Spark View 引擎的一件重要事情是它的语法与 HTML 语法非常相似,这样您的视图将是干净的,并且您将避免 WebForms View 引擎中的“标签汤”。
这是一个示例:

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>
<% }%>

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>
<% }%>
流年里的时光 2024-07-27 12:21:47

它避免了您经常看到的 HTML 标签汤。 考虑 Spark:

<ul>
  <li each='var p in ViewData.Model.Products'>
    ${p.Name}
  </li>  
</ul>

与经典的 html 标签汤变体相反:

<ul>
  <% foreach(var p in ViewData.Model.Products) { %>
  <li>
    <%= p.Name %>
  </li>
  <% } %>
</ul>

Spark 语法更加简洁。

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.

病女 2024-07-27 12:21:47

我真的很喜欢绑定功能。

您可以在绑定

中指定某些内容并使用漂亮的 xml 标记在你看来。

我们在视图中使用的所有 html 助手都有绑定,例如。
<文本框=“”/>
等等等等...

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文