ASP.NET Scaffolding is a code generation framework for ASP.NET Web applications. Visual Studio 2013 includes pre-installed code generators for MVC and Web API projects. You add scaffolding to your project when you want to quickly add code that interacts with data models. Using scaffolding can reduce the amount of time to develop standard data operations in your project.
Visual Studio 2013 does not currently support generating pages for a Web Forms project, but you can use scaffolding with Web Forms by adding MVC dependencies to the project.
To use ASP.NET Scaffolding, you must have:
- Microsoft Visual Studio 2013
- Web Developer Tools (part of default Visual Studio 2013 installation)
- ASP.NET Web Frameworks and Tools 2013 (part of default Visual Studio 2013 installation)
Add a scaffolded item to MVC or Web API
To add a scaffold, right-click either the project or a folder within the project, and select Add – New Scaffolded Item, as shown in the following image.
From the Add Scaffold window, select the type of scaffold to add.
The Add Controller window gives you the opportunity to select options for generating the controller, including whether you want to use the new async features from Entity Framework 6.
The relevant classes and pages are created for your scenario. For example, the following image shows the MVC controller and views that were created through scaffolding for a model class named Movies.
Add a scaffolded item to Web Forms
Currently, you cannot add scaffolding that generates Web Forms code. However, you can use scaffolding in a project that uses Web Forms by adding MVC dependencies. To add MVC dependencies, select Add - New Scaffolded Item. In the Add Scaffold window, select MVC Dependencies, as shown below.
There are two options for scaffolding MVC; Minimal and Full. If you select Minimal, only the NuGet packages and references for ASP.NET MVC are added to your project. If you select the Full option, the Minimal dependencies are added, as well as the required content files for an MVC project. To easily use scaffolding, select Full dependencies.
After adding the dependencies, you will see a readme.txt file. Carefully follow the instructions in this file to ensure that your project works correctly.
When you have completed the steps in the readme.txt file, you can add a new scaffolded item as shown in the previous section about MVC and Web API. The automatically-generated views and controller will function correctly within your project.
For an example of using scaffolding with Database First development, see EF Database First with ASP.NET MVC.
For an example of using scaffolding in an MVC project, see Getting Started with ASP.NET MVC 5.
For an example of using scaffolding in a Web API project, see Create a REST API with Attribute Routing in Web API 2.