T4MVC or MvcFutures for strongly typed links in views

安稳与你 提交于 2019-12-10 21:14:15

问题


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

  1. use MvcFutures and do something like:

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

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

Thoughts?


回答1:


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

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.

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




回答2:


T4MVC will perform better. The helpers in MvcFutures that you are interested in use expressions, which should be slower than the built-in methods (one of the reasons why those methods are not in the core MVC assembly). In general you should be aware that MvcFutures may have performance and other functional issues.



来源:https://stackoverflow.com/questions/5111212/t4mvc-or-mvcfutures-for-strongly-typed-links-in-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!