Using Scaffold Package to generate your MVC project.

This is a basic topic discussing about how existing scaffold template works while creating a new MVC Views in Razor.

When you try to create a View, you will get a window giving you all the options supported by Scaffolding. Like one showed in left.

All the options below View Engine drop-down will be enabled after you check "Create a strongly-typed View", where you have to select a Model. Thus showing Scaffolding is Model Dependant.

Once you select a model, Scaffold template drop down will be enabled, giving you options
1. Empty - Creates a Empty Controller.
2. CURD - Creates a model supporting all the CURD operations.

The Main objective is to see how this works from "Package Manager Console". As we work more with this console for customization of these templates going forward, we need to understand the basics.

Objective: Create a Employee Scaffold template from a EMP Model.

Step 1: Create a Model for Employee

Step 2: Now Open "Package Manager Console".
Visual Studio’s View->Other Windows->Package Manager Console
Step 3:It is assumed that you install MVC 3 framework. Now, Install the MVCScaffolding Package by using the command
"Install-Package MvcScaffolding".

Step 4: MVCScffolding is installed. Now, you need to use this package fro the Model we designed in Step1.
Use command "Scaffold Controller <Model Name>".

In the above image you can see the scaffolding package is trying to add the data context, controller, all the views required for CURD operations.

Please find the project structure after Scaffolding package taken care of Adding the required infrastructure for basic CURD operations.

We have done all this just by creating a model.

In next Post we will see different Options available in Scaffolding and the standard usage of them.

Is it helpful for you? Kindly let me know your comments / Questions.

No comments:

Post a Comment