Saturday, August 6, 2016

Creating Custom Scaffolding Templates for ASP.NET MVC and ASP.NET Web API

If you need to heavily customize the out-of-the-box templates that come with ASP.NET MVC and ASP.NET Web API, you can either create a brand new T4 Templates project or simply use the CodeTemplates directory functionality for Scaffolding that is already available with ASP.NET MVC and ASP.NET Web API!

You can read more about creating your own Custom Scaffolding Templates below:

All of these articles refer to paths from earlier versions of Visual Studio, so if you are wondering about the correct path for Visual Studio 2015, it is this:

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

Inside that folder, you will find the following folder structure which displays all of the possible default scaffolding templates that you can override by bringing it directly into your solution:

Once you have your Scaffolding templates in place, you can simply right click in your ASP.NET MVC or ASP.NET Web API project and select Add --> New Scaffolded Item:

This will then use your own custom Scaffolding Template instead of the out-of-the-box Scaffolding templates that ship with Visual Studio!  In addition, you can also add new Scaffolding templates as well that can further extend what ships with Visual Studio!

How cool is that??

No comments:

Post a Comment