Introduction
Microsoft released MVC 5 with Visual Studio 2013 Preview. As you know, CRUD Operations are done with MVC 4 in previous versions of Visual Studio. Now, in this article, I'll introduce you to how to create CRUD Operations by MVC 5. There are some changes in Visual Studio 2013 Preview for CRUD Operations by MVC 5.
In that context, I am developing an app in which you will learn how to access your Model's data from a Controller. For this, you need to read my previous article in which I introduced how to work with the Model Class and connection strings. For accessing your Model's Data from a Controller, you need to follow the steps given below:
- Scaffold
- Create
- Read
- Update
- Delete
- Connect with SQL Server LocalDB
Scaffold
Step 1: Before proceeding to the next step please build you solution. If you do not build your application then you might get an error when you add the Controller.

Step 2: Select your application in Solution Explorer.

Step 3: Right-click on your Controllers folder to add a Controller.

Step 4: After selecting scaffold, select MVC 5 Controller with read/write.

Step 5: Enter your Controller name as CricketersController, select your Model Class and Data context class.

Click the "Add" button to add a Controller named CricketersController. (If you get an error then maybe you did not build your solution before adding the Controller.) When you click on "Add", Visual Studio automatically creates and adds many files and folders to your application. You can view files and folders in your Solution Explorer.

You can also view you CRUD action methods like Create, Read, Update and Delete in your CricketersController.cs file. When you debug your application, open your application in the browser in URL format like "http://localhost:(your port number)/Cricketers". In that page you can Create, Read, Update and Delete your data as you want.

Now, let's move to the CRUD Operations.
Create
Now it's time to create some data in the application. Please follow the steps given below.
Step 1: Click on "Create New link".

Step 2: In the next window enter your data.

Step 3: Provide more data for edit and delete.
Read
It's time to read your data. To read the data, review the following steps.
Step 1: Click on "Create" after filling in the information.

















Girish TripathiPosted Oct 12, 2013, 4:44 AM
Very helpful..