ASP.NET MVC视图引擎比较 [英] ASP.NET MVC View Engine Comparison

查看:142
本文介绍了ASP.NET MVC视图引擎比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直很&放搜索的;谷歌为提供ASP.NET MVC,但各视图引擎的细分还没有找到比的视图引擎是简单的高级别描述等等。

I've been searching on SO & Google for a breakdown of the various View Engines available for ASP.NET MVC, but haven't found much more than simple high-level descriptions of what a view engine is.

我不一定寻找最佳或最快,而是一些现实世界中的优势比较/的主要参与者缺点(如默认WebFormViewEngine,MvcContrib视图引擎等)进行各种情况。我认为这将是真正有用的确定如果从默认引擎切换将是一个给定的项目或开发组是有利的。

I'm not necessarily looking for "best" or "fastest" but rather some real world comparisons of advantages / disadvantages of the major players (e.g. the default WebFormViewEngine, MvcContrib View Engines, etc.) for various situations. I think this would be really helpful in determining if switching from the default engine would be advantageous for a given project or development group.

有没有人遇到过这样的比较呢?

Has anyone encountered such a comparison?

推荐答案

由于COM prehensive列表中不存在的出现,让我们开始一个在这里的SO。这可能是很有价值的ASP.NET MVC社会,如果人们加入他们的经验(特别是人谁给其中的一个贡献)。任何实施 IViewEngine (例如 VirtualPathProviderViewEngine )这里是公平的游戏。只需按字母顺序排列的新视图引擎(离开WebFormViewEngine和剃刀在顶部),并尽量在比较客观的。

ASP.NET MVC View Engines (Community Wiki)

Since a comprehensive list does not appear exist, let's start one here on SO. This can be of great value to the ASP.NET MVC community if people add their experience (esp. anyone who contributed to one of these). Anything implementing IViewEngine (e.g. VirtualPathProviderViewEngine) is fair game here. Just alphabetize new View Engines (leaving WebFormViewEngine and Razor at the top), and try to be objective in comparisons.

System.Web.Mvc.WebFormViewEngine

System.Web.Mvc.WebFormViewEngine

设计目标:

这是用来渲染视图引擎
  Web窗体页面的响应。

A view engine that is used to render a Web Forms page to the response.

优点:


  • ,因为它附带了ASP.NET MVC
  • 无处不在
  • 对于ASP.NET开发人员熟悉的体验

  • 智能感知

  • 可以选择以codeDOM提供任何语言(如C#,VB.NET,F#,嘘,Nemerle)

  • 在按需编译或 precompiled 意见

  • ubiquitous since it ships with ASP.NET MVC
  • familiar experience for ASP.NET developers
  • IntelliSense
  • can choose any language with a CodeDom provider (e.g. C#, VB.NET, F#, Boo, Nemerle)
  • on-demand compilation or precompiled views

缺点:


  • 的使用是由经典ASP.NET模式存在混淆这在MVC(例如ViewState的回发)不再适用

  • 可以有助于标签汤
  • 反模式
  • code块语法和强类型可以得到的方式

  • 智能感知强制风格并不一定适合内嵌code块

  • 简单的设计模板时,可以吵

例如:

<%@ Control Inherits="System.Web.Mvc.ViewPage<IEnumerable<Product>>" %>
<% if(model.Any()) { %>
<ul>
    <% foreach(var p in model){%>
    <li><%=p.Name%></li>
    <%}%>
</ul>
<%}else{%>
    <p>No products available</p>
<%}%>


<一个href=\"http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx\">System.Web.Razor

设计目标:

优点:


  • 紧凑型,防爆pressive和流体

  • 易于学习

  • 是不是一种新的语言

  • 具有很大的智能感知

  • 单元测试

  • 无处不在的,附带的ASP.NET MVC

缺点:


  • 创建一个从上面提到的标签汤一个稍微不同的问题。当服务器变量实际提供各地的服务器和非服务器code结构,剃刀混淆HTML和服务器code,使得纯HTML或JS发展挑战(见精读实例#1)当你最终不得不逃离HTML和/或JavaScript在某些常见情况标签。

  • 可怜的封装+可重用性:这是不切实际的,叫剃刀模板,就好像它是一个正常的方法 - 在实践剃须刀可以调用code,但不是相反,这可以鼓励code和$ P $的混合psentation。

  • 的语法很HTML导向;生成非HTML内容可能会非常棘手。尽管这样,剃刀的数据模型本质上只是字符串拼接,所以语法和既不是静态的,也没有检测到动态嵌套错误,但是VS.NET设计时帮助缓解这个有点。可维护性和可refactorability遭受缘于此。

  • <击>无记录API ,<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.razor.aspx\">http://msdn.microsoft.com/en-us/library/system.web.razor.aspx

  • Creates a slightly different problem from "tag soup" referenced above. Where the server tags actually provide structure around server and non-server code, Razor confuses HTML and server code, making pure HTML or JS development challenging (see Con Example #1) as you end up having to "escape" HTML and / or JavaScript tags under certain very common conditions.
  • Poor encapsulation+reuseability: It's impractical to call a razor template as if it were a normal method - in practice razor can call code but not vice versa, which can encourage mixing of code and presentation.
  • Syntax is very html-oriented; generating non-html content can be tricky. Despite this, razor's data model is essentially just string-concatenation, so syntax and nesting errors are neither statically nor dynamically detected, though VS.NET design-time help mitigates this somewhat. Maintainability and refactorability can suffer due to this.
  • No documented API, http://msdn.microsoft.com/en-us/library/system.web.razor.aspx

体质例子#1(注意的安置的String [] ...):

Con Example #1 (notice the placement of "string[]..."):

@{
    <h3>Team Members</h3> string[] teamMembers = {"Matt", "Joanne", "Robert"};
    foreach (var person in teamMembers)
    {
        <p>@person</p>
    }
}


贝尔维尤


Bellevue

设计目标:


      
  • 尊重HTML作为一流的语言,而不是把它当作只是文字。

  •   
  • 请不要惹我的HTML!数据绑定code(贝尔维尤code)应该从HTML分开的。

  •   
  • 执行严格的模型 - 视图分离

  •   

抄网


Brail

设计目标:

,触觉视图引擎已经被移植
  从单轨与合作
  微软ASP.NET MVC框架。对于
  介绍抄网,请参阅
  在城堡项目文档
  网站

The Brail view engine has been ported from MonoRail to work with the Microsoft ASP.NET MVC Framework. For an introduction to Brail, see the documentation on the Castle project website.

优点:


  • 后腕友好Python语法
  • 建模
  • 在按需编译的意见(但没有可用的precompilation)

缺点:


  • 设计要写入的语言

  • designed to be written in the language Boo

例如:

<html>    
<head>        
<title>${title}</title>
</head>    
<body>        
     <p>The following items are in the list:</p>  
     <ul><%for element in list:    output "<li>${element}</li>"%></ul>
     <p>I hope that you would like Brail</p>    
</body>
</html>


Hasic


Hasic

Hasic使用VB.NET的XML文本,而不是像大多数其他视图引擎的字符串。

Hasic uses VB.NET's XML literals instead of strings like most other view engines.

优点:


  • 编译时有效的XML的检查

  • 语法着色

  • 完整的IntelliSense

  • 编译意见

  • 经常使用CLR类,功能,可扩展性等

  • 无缝组合性和操纵,因为它是常规的VB.NET code

  • 单元测试

缺点:


  • 性能:它发送到客户端之前构建整个DOM。

例如:

Protected Overrides Function Body() As XElement
    Return _
    <body>
        <h1>Hello, World</h1>
    </body>
End Function


NDjango


NDjango

设计目标:

NDjango是的一个实施
   Django的模板语言的基于.NET
  平台,使用 F#语言

NDjango is an implementation of the Django Template Language on the .NET platform, using the F# language.

优点:

NHaml

NHaml

设计目标:

.NET的Rails的Haml的视图引擎端口。
  从的Haml的网站

.NET port of Rails Haml view engine. From the Haml website:

Haml的是所使用的标记语言
  干净和简单的描述
  任何web文档的XHTML,而不
  使用内嵌code的... Haml的避免
  需要明确的编码成XHTML
  模板,因为它实际上是
  在XHTML的抽象描述,
  一些code生成动态
  内容。

Haml is a markup language that's used to cleanly and simply describe the XHTML of any web document, without the use of inline code... Haml avoids the need for explicitly coding XHTML into the template, because it is actually an abstract description of the XHTML, with some code to generate dynamic content.

优点:


  • 简洁的结构(即D.R.Y。)

  • 以及缩进

  • 结构清晰

  • C#智能感知(VS2008为ReSharper的无)

  • terse structure (i.e. D.R.Y.)
  • well indented
  • clear structure
  • C# Intellisense (for VS2008 without ReSharper)

缺点:


  • 从XHTML的抽象,而不是利用标记的熟悉

  • 没有智能感知为VS2010

例如:

@type=IEnumerable<Product>
- if(model.Any())
  %ul
    - foreach (var p in model)
      %li= p.Name
- else
  %p No products available


NVelocityViewEngine(MvcContrib)


NVelocityViewEngine (MvcContrib)

设计目标:

一个视图引擎基于
   NVelocity 这是一个.NET端口
  流行的Java项目
  速度

A view engine based upon NVelocity which is a .NET port of the popular Java project Velocity.

优点:


  • 易于读取/写入

  • 简练code

缺点:


  • 在视图中可用的有限数量的helper方法

  • 不自动具有Visual Studio集成(智能感知,编译时的检查意见,或重构)

例如:

#foreach ($p in $viewdata.Model)
#beforeall
    <ul>
#each
    <li>$p.Name</li>
#afterall
    </ul>
#nodata 
    <p>No products available</p>
#end


SharpTiles


SharpTiles

设计目标:

SharpTiles是 JSTL 的部分端口
  结合瓷砖背后的理念
  框架
(如里程碑1)。

SharpTiles is a partial port of JSTL combined with concept behind the Tiles framework (as of Mile stone 1).

优点:


  • 熟悉的Java开发人员

  • XML风格code块

缺点:


  • ...

例如:

<c:if test="${not fn:empty(Page.Tiles)}">
  <p class="note">
    <fmt:message key="page.tilesSupport"/>
  </p>
</c:if>


星火视图引擎


Spark View Engine

设计目标:

的想法是允许的HTML,以
  主宰流动和code,以适应
  无缝连接。

The idea is to allow the html to dominate the flow and the code to fit seamlessly.

优点:


  • 生成更可读的模板

  • C#智能感知(VS2008为ReSharper的无)

  • SparkSense插件为VS2010(适用于ReSharper的)

  • 提供了强大的绑定功能摆脱的所有的$ C $在C你意见及让您轻松创造自己的HTML标签

  • Produces more readable templates
  • C# Intellisense (for VS2008 without ReSharper)
  • SparkSense plug-in for VS2010 (works with ReSharper)
  • Provides a powerful Bindings feature to get rid of all code in your views and allows you to easily invent your own HTML tags

缺点:


  • 从字面标记模板的逻辑没有明确分离(这可以通过命名空间prefixes得到缓解)

例如:

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

<Form style="background-color:olive;">
    <Label For="username" />
    <TextBox For="username" />
    <ValidationMessage For="username" Message="Please type a valid username." />
</Form>


StringTemplate的视图引擎MVC


StringTemplate View Engine MVC

设计目标:


      
  • 轻。无分页类创建。

  •   
  • 快速。模板被写入到响应输出流。

  •   
  • 缓存。模板缓存,但利用FileSystemWatcher的检测
      文件更改。

  •   
  • 动态。模板可以在code实时生成。

  •   
  • 灵活。模板可以嵌套到任何级别。

  •   
  • 在与MVC原则。促进UI和业务分离
      逻辑。所有数据被创建提前
      时间,并通过发送到模板。

  •   

优点:


  • 熟悉StringTemplate的Java开发人员

缺点:

  • simplistic template syntax can interfere with intended output (e.g. jQuery conflict)

永节拍

Wing Beats

永节拍是创建XHTML内部DSL。它是基于F#,并包括一个ASP.NET MVC视图发动机,但也可以为其创建的XHTML能力单独使用。

Wing Beats is an internal DSL for creating XHTML. It is based on F# and includes an ASP.NET MVC view engine, but can also be used solely for its capability of creating XHTML.

优点:


  • 编译时有效的XML的检查

  • 语法着色

  • 完整的IntelliSense

  • 编译意见

  • 经常使用CLR类,功能,可扩展性等

  • 无缝组合性和操纵,因为它是常规的F#code

  • 单元测试

缺点:


  • 您真的不写HTML,但code,稀土presents HTML的DSL。

XsltViewEngine(MvcContrib)

XsltViewEngine (MvcContrib)

设计目标:

从构建XSLT熟悉意见

Builds views from familiar XSLT

优点:


  • 广泛普及

  • XML开发熟悉模板语言

  • 基于XML的

  • 经过时间考验

  • 的语法和元素嵌套错误可以被检测静态

缺点:


  • 函数式语言风格使得流量控制困难

  • XSLT 2.0是(可能?)不支持。 (XSLT 1.0是更实用)。

这篇关于ASP.NET MVC视图引擎比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆