This is ASP.NET MVC 5 Tutorial Part-2 in series of building ASP.NET MVC Application using Entity Framework. In previous part, we built a simple ASP.NET MVC application (Product Catalog Application) and generate an EDM(Entity Data Model) following a step by step approach. We also got answers to:
- What an ORM is?
- Entity Framework as an ORM?
- What is an EDM(Entity Data Model)?
In this part of ASP.NET MVC tutorial, we are going to generate views for our model classes. So, I’ll highly recommend to go through previous post for understanding about our EDM(Entity Data Model). Before we start implementation of generating views, let’s first understand a relevant concept i.e. Scaffolding.
What is Scaffolding in MVC?
In Software industry, Scaffolding is generally used as a way to generate some base code for a software that can be further customized or enhanced. So, Scaffolding in MVC is basically a code generation template that facilitate us to generate code for Controllers and Views etc.
You can find a comprehensive list of Entity Framework Interview Questions for beginners as well as experienced developers here.
For the purpose of this implementation, we will be using ASP.NET MVC scaffolding to automatically generate code for controller, it’s methods and related views against our model classes. Let’s take a look to our EDM(Entity Data Model) diagram:
Choose “MVC 5 Controller with views, using Entity Framework” option from Add Scaffold screen.
- Controller name as “ProductController“.
It will add a ProductController under Controllers folder.
- Model class as “Product (MyProductCatalog.Models)“.
Product class under MyProductCatalog.Models will be considered as Model to generate controller and views using MVC Scaffolding.
- Data context class as “ProductCatalogEntities (MyProductCatalogModels)“.
ProductCatalogEntities class under MyProductCatalogModels will be our Data context class.
Now, we can see that above given steps not only created “ProductController” under Controllers folder but also create “Product” folder under Views folder, containing views for all CRUD operations as:
ASP.NET MVC Scaffolding did a lot for us. We will go through the generated code for controller as well as view later in a separate post on this blog but let’s try to run the application now. In order to see the application running properly, right click on Index.cshtml and choose “View in Browser”.
We can follow the same steps for creating all Controller and respective Views for our Category Model also. Finally, I’ll recommend to go through the generated code for our Controller and Views and try to make changes and see the output.
Previous << Part 1 – Building ASP.NET MVC Entity Data Model
Other ASP.NET MVC 5 and Related Tutorial:
- MVC3 Vs MVC4 Vs MVC5
- A practical guide to ASP.NET Web API
- Building your First ASP.NET MVC 5 Application
- WebForms Vs ASP.NET MVC
- Solution to browser back button event
- What’s new in WCF 4.5
- WCF Tutorial step by step
- Creating your first WCF REST Service
Top 10 Interview Questions and Answers Series:
- Top 10 HTML5 Interview Questions
- Top 10 ASP.NET Interview Questions
- Comprehensive Series of ASP.NET Interview Questions
- Top 10 ASP.NET MVC Interview Questions
- Top 10 ASP.NET Web API Interview Questions
- Top 10 ASP.NET AJAX Interview Questions
- Top 10 WCF Interview Questions
- Comprehensive Series of WCF Interview Questions