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.
Your project structure should look like this:
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:
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:
Of course, there are a lot of other advantages of using MVC Scaffolding, such as: adding Interfaces etc.
Isn’t this great?