How to create custom scaffold templates in ASP.NET MVC5?

前端 未结 5 1674
傲寒
傲寒 2020-12-03 06:01

I\'m using ASP.NET MVC5 and VS2013

I\'ve tried to copy CodeTemplates folder from

C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Commo

5条回答
  •  佛祖请我去吃肉
    2020-12-03 06:41

    MVC4 and MVC5 templates are located in different locations. While MVC4 templates are located in the folder you've given, MVC5 templates are located in this folder:

    C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates

    What you need to do for customizing is to create a folder named CodeTemplates your project folder, and copy the templates you want to customize to the CodeTemplates folder.

    You'll need to copy MvcView and MvcControllerWithContext folders in order to use with MVC 5 Controller with view, using EntityFramework command.

    CAUTION

    • Both directories must have the same folder structure. What I mean is, do not copy the Create.cs.t4 in the MvcView folder directly into the CodeTemplates folder. Just copy the entire MvcView folder into CodeTemplates folder.

    • Do not delete include files such as Imports.include.t4 and ModelMetadataFunctions.cs.include.t4 because other files need them to be there.

    • If you're using C#, feel free to delete files with .vb.t4 extension and vice versa.

提交回复
热议问题