本文介绍了T4MVC或在景色强类型的链接MvcFutures的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图降低我的MVC3项目/消除魔术字符串,并想知道哪种方法会更好:

I am trying to reduce/eliminate "magic strings" from my MVC3 project and was wondering which approach would be better:


  1. 使用MvcFutures,做类似:

  1. use MvcFutures and do something like:

var title = "Create New Customer"; 
Html.ActionLink
    (c => c.Create(), title , new { @class = "button", title = title });


  • 使用

    哪种选择更灵活,更高性能,更易于重构的时候,等,等?

    Which option is more flexible, more performant, easier when refactoring, etc, etc?

    思考?

    推荐答案

    T4MVC,没有比赛。它让你参考使用(code生成)嵌套类和属性的层次结构视图和控制器动作。这种方法有几个好处 - 可用的选项很容易被发现的,它提供了最佳的性能(当然是一个巨大的胜利相比,强类型的λ-方法)。

    T4MVC, no contest. It let's you reference views and controller actions using a hierarchy of (code-generated) nested classes and properties. This approach has several benefits - available options can easily be discovered, and it provides the best possible performance (certainly a big win compared to the lambda-approach for strong typing).

    这也很容易编写使用T4MVC的虚拟类的ActionResult自己的扩展。例如,我有一些ActionImage助手即提取必要的路由信息​​生成结果的标记。

    It's also very easy to write your own extensions that use T4MVC's dummy ActionResult class. For instance, I have some ActionImage helpers that extract the necessary routing information to generate the resulting markup.

    唯一的缺点T4MVC的是,你需要不断的产生code文件保持最新状态。您可以通过保持.TT打开文件,或通过安装会自动运行.TT文件(例如扢)延伸做到这一点。

    The only downside to T4MVC is that you need to keep the generated code file up to date. You can do this by keeping the .tt file open or by installing an extension that will run .tt files automatically (e.g. Chirpy).

    这篇关于T4MVC或在景色强类型的链接MvcFutures的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 10-22 09:23