Introduction
This article describes ASP.NET Scaffolding in Visual Studio 2013, which is a new feature of Visual Studio 2013. It is a code generation framework for the ASP.NET Web Applications. This scaffolding is installed already for MVC and Web API Project Templates.
Overview
Why use scaffolding? Scaffolding is used when we want to add code that interacts with our models. The use of Scaffolding brings the standard structure to the application, it reduces the amount of time of developing any operations in the application. The ASP.NET Web Applications that are developed in the Web Forms Project Template does not support scaffolding as a default, but we can use the scaffolding with the Web Forms by either using the MVC Dependencies to the project or installing an extension. You can show it later in here.
Now you can also customize the scaffolding by updating the Visual Studio 2013 to the Released Candidate update of Visual Studio. You can refer to Custom Scaffolder for Visual Studio 2013 for further reference.
Prerequisites
You must have the following prerequisites for working with the ASP.NET Scaffolding:
- Visual Studio 2013
- Web Developer Tools
Scaffolding in MVC or Web API
In this section, we'll see how to use the scaffolding in MVC or Web API. Let's start with the following sections.
Step 1: Create the ASP.NET web application in the MVC Project Template.
Step 2: Right-click on the Controllers folder to add a new scaffolded item in Solution Explorer
Step 3: In the next Add Scaffold wizard, select the MVC 5 Controller as in the following:
Step 4: Now in the next Add Controller wizard, when you enter the Model Class, the controller name is generated automatically and the DataContext class is also selected.
Step 5: Just click on Add to scaffold. Please note that you build your solution at first otherwise it will give you an error. After scaffolding you can check that your Solution Explorer contains the new files and folders related to scaffolding.
Web Forms Scaffolding
We can add the Web Forms Scaffolding that generates the Web Forms code by installing it by Extensions and Update wizard in the application .
Step 1: Go to Tools-> Extensions and Updates.
Step 2: Enter the Web Forms Scaffolding and select the Online from the right pane as in below:
MVC Dependencies
You can also add the MVC Dependencies from the Add Scaffold wizard as in below:
When you select this option, the next wizard opens the named Add MVC Dependencies having two options Minimal dependencies and Full dependencies. When we select the Minimal, only the NuGet references are added for the MVC project and if we select the Full, the Minimal dependencies and as well as more content files are added to the MVC application. Select Full Dependencies to use scaffolding simply.
Next, you'll receive the readme.txt file and you need to complete the steps that are defined in that file.
That's it.
Summary
This article has helped you to learn scaffolding in ASP.NET web applications with MVC or Web API Project Templates in Visual Studio 2013. Thanks for reading.