- Visual Studio 2010
- Apache License, Version 2.0
- ADO.NET Entity Framework
- ASP.NET MVC 3
- Master Detail CRUD with MVC 3 and EF
- 01/17/2012
A sample Visual Studio project which shows how to perform Master-Detail CRUD operation using Entity Framework (Code First Approach) and ASP.net MVC 3.
The code illustrates the following topics:
• Creating a data model (SalesMain and SalesSub).
• Performing Master-Detail CRUD operations.
• AJAX post and JSON Data Passing
To build and run this sample, you must have Visual Studio 2010 SP1 and MVC 3 with the MVC 3 Tools Update installed. Extract the master_detail_MVC3.zip file and open MasterDetail.sln solution.
Running Sample
Open the solution. Press Ctrl and F5.
Then Go to Sales Tab.
Fig 1: Creating New Sales Record with multiple sales Sub Record
Fig 2: Editing existing Sales Record with multiple sales Sub Record
- App_Data folder - Holds the SQL Server Compact database file.
- Content - Holds CSS files.
- Controllers - Holds controller classes.
- Models folder - Holds model classes.
- Properties or MyProject folder - Project properties.
- Scripts folder - Script files.
- Views folder - Holds view classes.
- Global.asax file - Includes database initializer code.
- Web.config file - Includes the connection string to the database.
- SalesMain.cs Model Class
- SalesSub.cs Model Class
- MasterDetailContext.cs Data Context Class
- SalesController.cs Controller
- Create.cshtml Create and Edit View
- Delete.cshtml Delete View
- Details.cshtml Details View
- Index.cshtml List View