问题
I am trying to reduce/eliminate "magic strings" from my MVC3 project and was wondering which approach would be better:
use MvcFutures and do something like:
var title = "Create New Customer"; Html.ActionLink (c => c.Create(), title , new { @class = "button", title = title });
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