ASP.MVC:实施非模板视图引擎? [英] ASP.MVC: Implementing a non-templated view engine?

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

问题描述

我是相当新的ASP.MVC。对于新的Web应用程序,我两个选择之间考虑视图引擎:

I'm fairly new to ASP.MVC. For our new Web application I'm considering between two options for view engines:


  1. 使用一些可用的视图引擎(默认的,NVelocity,抄网等)为主视图code发生器。

  2. 实现了这样的看法code的主要大宗存储在C#类(使用某种形式的智能生成HTML像吉米·博加德所述)。

  1. Using some of the available view engines (the default one, NVelocity, Brail, etc.) as a primary view code generator.
  2. Implementing an application-specific C# DSL for generating HTML code so that the main bulk of the view code is stored in C# classes (using some sort of smart HTML generation like the one described by Jimmy Bogard).

2,背后的想法是,以减少直接编写HTML $ C $每次需要一个新的视图时间C的需要,但我不知道这是否是一个不错的办法。它的一个缺点是,它不可能改变所产生的code而无需重新编译该项目。

The idea behind 2. would be to reduce the need for writing direct HTML code each time a new view is needed, but I'm not sure if this is a good approach. One drawback of it is that it would not be possible to change the generated code without recompiling the project.

你怎么想的?

推荐答案

我见过像这样在其他项目中使用的方法,一般他们更麻烦比他们的价值。你失去了灵活性,只是过高的价格来支付生成阶段的自动岬。想想要求多久转出申请只是一种特殊情况,现在想象你怎么也来处理这里。

I've seen approaches like this used in other projects, and in general they're more trouble than they're worth. The flexibility you lose is just too high a price to pay for the automatic-ness of the generation phase. Think of how often requirements turn out to apply just to one special case, and now imagine how you'd have to handle that here.

此外,如果你的意见是造成你的痛苦,我会建议你可能不正确使用视图。您应该看到整个网站的意见很少重复。通用件应被重构到单独的块,并从那里拉入,例如。

Additionally, if your views are causing you that much pain, I would suggest you might not be using views correctly. You should see very little repetition in your views across the site. Common pieces should be refactored into separate chunks and pulled in from there, for example.

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

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