Thursday, May 10, 2012

Customizing ASP.Net MVC Template scaffold templates for controller and view are really useful but often we need to change the default template to fit with particular project. It's easy to do. Follow the steps below to customize the ASP.Net MVC3 built-in T4 template:

  1. Go ahead and find the default template from the following location- 
  2. [Visual Studio Installation Directory]\Common7\IDE\ItemTemplates\CSharp\Web\MVC 3 
  3. Copy the "CodeTemplates" folder. 
  4. Paste the "CodeTemplates" folder to the project's root. 
  5. Remove the templates(extension '*.tt') that you do not need to customize from the project's "CodeTemplates" folder. 
  6. Select the templates(press and hold ctrl and click on the template) and go to properties(right click and select properties). 
  7. Clear "Custom Tool" entry. By doing this, it will not run the template automatically every time you build the project. 
  8. Now customize the template as you want and build the project. 
  9. Right click on View folder and select add view. From the add view popup dialog box, select the model class and you will find the customized template in the "scaffold template" drop down list. 

 Happy Programming!

No comments: