Raj Aththanayake's Blog Raj Aththanayake's Blog | Getting Started with T4MVC

Getting Started with T4MVC

24. April 2011

This post is about T4MVC and how you would use it within your MVC application. T4MVC is a great way to generate strongly typed helpers so you can eliminate the use of literal strings when referring to Actions, Controller, and Views within your MVC application.

How to install T4MVC?

You have 2 options.

a.    Download from MvcContrib CodePlex project. http://mvccontrib.codeplex.com/releases/view/41582


b.    Use NuGet



NuGet Approach      

Open VS2010. Tools,  Library Package Manager, and Package Manager Console. Execute the following command.

PM> install-package T4MVC

This should install 2 files under your app’s root folder.

T4MVC.tt and T4MVC.tt.settings.t4 - These files contain necessary entries which allow you to use T4 strongly typed helpers.


Once you install T4MVC, you might also notice couple errors appeared in the Error List window. (Please see below)  


As you see, there are no auto generated files being added to the solution yet. You would continue to get these errors if you decided to build the solution.

To remove these errors, you need to run Custom Tool on the T4MVC.tt file. (Right click on the file and select “Run Custom Tool”).Now you should be able to see additional auto generated files added to the solution.


T4MVC in Action

Below are few examples of the usage of T4MVC.



As you see T4MVC generates the strings accordingly.

Where to find more information?

T4MVC templates are part of MVCContrib project and developed by David Ebbo. If you would like to know more information please visit the link below.




Comments are closed