Building your first ASP.NET MVC 4 application in VS 2012 – using MVC Scaffolding

Previously I wrote a post about creating a simple ASP.NET MVC 4 application. I have told you, that it is so simple. Today you will see that it can be easier with MVC scaffolding.

 

1. Open Visual Studio 2012

2. File/New/Project -> select Web/ASP.NET MVC 4 Web Application. Name it MvcCars.

3. When new window appears, please select a template as Internet Application and the vie engine as Razor. For this example, please do not select Create a unit test project.

4. Confirm

Your project structure should look like this:

1

 

We will start from creating a new model class. To do this, please right click on folder Models, select Add->New Item and choose Class. Name it as Car.cs – it is our first POCO in a project. The next thing is to add primitive properties inside of a class as below:

2

 

Ok. Now you can say that it looks exactly the same as in https://mjedrzejewski.wordpress.com/2013/09/09/building-your-first-asp-net-mvc-4-application-in-vs-2012/

Yes. It does. But the the fun is just getting started.

Go to the Tools/Library Package Manager and select Package Console Manager. You need to write as input PM> install-package MvcScaffolding and click Enter. MVC scaffolding package will start installing.

Ok, what’s next?

Go to the Package Console Manager and write as input PM> Scaffold Controller Car 

Wait until everything is done. You will see that all: Controller with CRUD methods, Views for Cars and Context class appear! Without writing any line of code, after you have prepared the model class. Your project structure should be similar to the previous one:

1

 

Of course, there are a lot of other advantages of using MVC Scaffolding, such as: adding Interfaces etc.

Isn’t this great?

 

 

 

One thought on “Building your first ASP.NET MVC 4 application in VS 2012 – using MVC Scaffolding

Zostaw komentarz

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s