ASP.NET MVC custom T4 templates for views

折月煮酒 提交于 2019-11-27 12:28:06

问题


When I'm adding a new strongly-typed view to an ASP.NET MVC project, I can select between different view content templates (Create Details, Edit, List). I have read these are templates based on the Visual Studio T4 code generation engine.

How can I author and configure my own templates and let them appear in the available templates when adding a new view?


回答1:


ASP.Net MVC - T4 Fun

T4 Templates: A Quick-Start Guide for ASP.NET MVC Developers




回答2:


Create following folder structure:

{YourMVCProject}\CodeTemplates\AddView

Put your custom T4 templates (*.tt) in this folder. You will see the magic!




回答3:


You might want to take a look at David Hayden's site: http://www.pnpguidance.net/Tag/T4.aspx -- He offers several screencasts on T4 and MVC that got me started. Also take a look at the T4 toolbox: (www.codeplex.com/t4toolbox). This provides additonal helpers for T4 templates.




回答4:


You can add a package to your project using NuGet that will add the existing code templates to your project. From that point you could edit them or just create new ones in the same location and you should see them in the tooling.

http://nuget.org/List/Packages/Mvc3CodeTemplatesCSharp



来源:https://stackoverflow.com/questions/1009067/asp-net-mvc-custom-t4-templates-for-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!