tags:

views:

32

answers:

3

I would like for the generate "List" view contents to have a check added to it to first check that the model has elements, it occurs to me that I have no idea how these views are generated. Can those be changed?

+1  A: 

Visual Studio uses "T4" (Text Template Transformation Toolkit) templates to generate the code when you ask for a new file, and yes, they can be edited.

Basically, you find the default templates, copy them into your project, and then edit them to create project-specific custom new-item templates which VS will use instead of the defaults.

A good set of basic instructions can be found at:

http://blogs.msdn.com/webdevtools/archive/2009/01/29/t4-templates-a-quick-start-guide-for-asp-net-mvc-developers.aspx

Eric King
That's a great link.
Anthony Potts
+1  A: 

They are T4 templates located in:

Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 2\CodeTemplates\AddView

Also take a look at this article, it describes how to change the templates on a per project basis.

Stephen Pence
Ahh, that's what T4 is used for. I have seen the terminology, but I'm usually too busy to play around with new technology unless I think I am close to using it.
Anthony Potts
I see in your path that you are using VS2010. How do you like it so far?
Anthony Potts
I have only been using it for a couple of days (since RTM), but so far I like it a lot, especially multi monitor support and the new Html encoding syntax in MVC 2/.Net4
Stephen Pence
+1  A: 

There is also another option, where in the MVC project you can make a folder called CodeTemplate and put the .tt files in there. Then those templates will be used as well.

Anthony Potts