Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

This tutorial will help you to get started with ASP.NET MVC

Getting started with ASP.NET MVC

Getting Started with ASP.NET MVC - Part 7: Scaffolding with ASP.NET MVC

May 29 2012 12:00AM by Jalpesh   

In the previous chapter, we have learnt about how we use entity framework to create database layer and how we can easily use this in ASP.NET MVC Application. In this chapter, we are going to learn how we can use scaffolding technique to create a basic CRUDE application without writing any code.

What is Scaffolding:

In programming, Scaffolding is a technique through we can create some classes and some code from the model class or the database structure.

Scaffolding can be beneficial in certain scenarios like following.

  1. If you are learning MVC and you don’t know much about ASP.NET MVC, then at that time it will definitely help you to understand the structure of the ASP.NET.
  2. You want to explore some new things or add-on for visual studio or any other technique, then at that time you can quickly create a CRUD operation without wasting your time.

Following are some of the features that are supported in scaffolding:

  1. Supports VB.NET and C# both language
  2. It also supports stand view engines so we don’t have to create HTML code also.
  3. It will also take care about the existing master page template and CSS styles

How Scaffolding works:

Now, let’s see how it works. I am going to use same application and same database structure that we have used in previous chapter.

Therefore, as we know we have a table called users with userid as primary key. Following is a structure of User table:

Table User

In addition, I have also inserted some data into table for viewing purpose. So once we have our scaffolidng complete, at that time we can see the data in our application. Therefore, I have inserted data as follows:

Table's data

Now we also have our Entity Framework Model class ready as following:

Edmx File

So now, we have all the prerequisites that we need to create a basic CRUD application with scaffolding. Please make sure you compile your application before starting the Scaffolding with ASP.NET MVC, as we need to have our model classes ready based on that we can use scaffolding. So now, once you are done with all this, right click controller folder and select Add and then add Controllers as follows:

Controller

Once you click on Controller, It will open up a add controller dialog like following:

Add Controller

Here you can see that there are several options in the dialog box. The first option is template which template you want to use. There are three options for that:

  • Empty Controller
  • Controller with Read/Write actions and Views, using entity framework
  • Controllers with Empty/Read write operations.

Another option for choosing model classes where I have chosen our user model class.

Last option is views where I can select user view.

Now click Add, it will create all view controller like following:

Controllers and Views

Therefore, you can see that without writing any code we have created our application. So, it’s now time to run our application and see whether it is actually working or not. So once you run application, you will be first presented to the User View where you have all the data, which we have inserted into the application like following:

User View

As you can see, data, which we have in database directly without writing code. In addition, there is a Create New link there on the top as well as also there are edit, details and delete links. Once you click Create New, following screens will presented to you where you have all the validation and other things ready like following:

Create New

Once you insert data and click on Create, it will redirect back to you all users view. Same way, you have all other functionalities ready. Once you click Edit from user’s grid, it will be redirected back to you with details pre-populated.

Edit Users

Same way once you click on Details link from users grid you will be redirected to the details page like following:

Details

So, as you can see, this is very easy and we can create a Basic CRUD application without writing any code from the model classes.

In next chapter, we will understand code for writing CRUD application in ASP.NET.


Jalpesh
15 · 11% · 3478
7



Submit

Your Comment


Sign Up or Login to post a comment.

"Getting Started with ASP.NET MVC - Part 7: Scaffolding with ASP.NET MVC " rated 5 out of 5 by 7 readers
Getting Started with ASP.NET MVC - Part 7: Scaffolding with ASP.NET MVC , 5.0 out of 5 based on 7 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]