T4 Templates: A Quick-Start Guide for ASP. net mvc Developers

Source: Internet
Author: User

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

 

Simply put, this is an industry-recognized code generation mechanism. T4 means: Text Template Transformation Toolkit

MVC uses T4 as the code generation template, which allows users to customize the Controller and View templates.

These templates are in the following directory

F: \ Program Files \ Microsoft Visual Studio 9.0 \ Common7 \ IDE \ ItemTemplates \ CSharp \ Web \ MVC 2 \ CodeTemplates \

The template is roughly as follows:

What are the main special variables that can be used in the template? See the following introduction.


Add Controller:

Property Name

Type

Description

ItemName

System. String

The name of the Controller class, including the 'controller' suffix

NameSpace

System. String

The namespace into which the Controller is being generated

ExtraActionMethods

System. Boolean

Indicates whether or not the user checked the option in the Add Controller dialog to get extra action methods

ControllerRootName

System. String

The name of the controller class without the 'controller' suffix

Add View:

Property Name

Type

Description

ItemName

System. String

The name of the view (without extension), as typed in the Add View dialog

NameSpace

System. String

The default namespace of the view's parent folder

IsViewUserControl

System. Boolean

Evaluates to true if the user chose a partial view in the Add View dialog

IsViewContentPage

System. Boolean

Evaluates to true if the user is creating a view with a master page

IsViewPage

System. Boolean

Evaluates to true if the user is creating a regular view page

MasterPage

System. String

Path to the master page the user chose in the dialog (to be used only when IsViewContentPage is true)

ContentPlaceholder

System. String

Name of the primary content place holder into which the generated content will be placed. This is the content place holder id the user typed into the Add View dialog

ContentPlaceHolders

System. Collections. Generic. List <System. String>

A list of all content place holder ID's in the master page, if a master page was chosen for this view

LanguageExtension

System. String

The output file's extension (including the period)

ViewDataTypeGenericString

System. String

This is a string that is used to output the generics clause for the 'explores' attribute in the view's ctictive (for stronugly-typed views ). example: "<MyType>" or "(Of MyType )"

ViewDataType

System. Type

This is a Type object representing the type to which a stronugly-typed view is bound. It can be used to get information on the properties in the type and the like


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.