CRUD Operation Entity Framework With MVC - Part 2

I have already written an article about CRUD Operation Entity Framework with MVC Application. Here's the link:

After adding Database .edmx file rebuild solution.

Controller handles HTTP Request and Response in database. Controller is the heart of MVC Architecture.

Right click the Controllers folder and then open the context menu. In the context menu Add -> Controller and then click Controller Label (Figure 1.1)

Add new controller
                                                               Figure 1.1

Open Add Controller windows and enter Controller Name. You can use Scaffolding features and then select Template.

Other templates available are Empty MVC Controller, Empty MVC Controller With Read/Write.

Select Model Class table name Like “EmpMst” as in the following figure 1.2:

EmpMst
                                                            Figure 1.2

Select Data Context class (CRMEntities) and also select View Types.

All available ContextClass in Figure 1.3

ContextClass
                                                            Figure 1.3


After that select DataContext class and views. Click Add button for adding Controller. (Figure 1.4)

adding Controller
                                                               Figure 1.4

Figure 1.5 shows Red Box as controller and Black Box as views.

Scaffolding features are automatically adding Views and Controller in Action Result.

Figure 1.5 also shows Action Result in EmpController.cs file.

EmpController
                              Figure 1.5

RouteConfig.cs file shown adding routes in red box. (Figure 1.6),

Nameis always different.

RouteConfig.cs
                                                                  Figure 1.6

Red box set ActionLink master Page (Figure 1.7)

Action link arguments Label, Second Action, Controller.

Action Link First Arguments
                                                                  Figure 1.7

After that run Application to click Employee tab.

See Index View and add new record. After that click Create New link as in the following figure 1.8:

Add New Record
                                                                        Figure 1.8

Add Employee Details Name, Phone No, Email, etc.

See Figure 1.9 for creating a view.

Create
                                                            Figure 1.9

Set Id as Primary Key table in Action result (Figure 1.10)

Action Result
Figure 1.10


Black Box as Employee Details and red box to perform actions like Edit, Delete, Details in particular Employee. (Figure 1.11)

Employee Details
                                                                  Figure 1.11

As in the preceding figure 1.11, click on the first record Edit link. The Edit View hidden field is Primary key column of table.

Current record changes EmpName. (Figure 1.12)

Edit
                                                           Figure 1.12

Here's the red box in Update record (Figure 1.13).

Index
                                                         Figure 1.13

As in figure 1.11 click Details link to see the details of individual employee. (Figure 1.14)

Details
                                                               Figure 1.14

All the operations directly affect the database. It cannot store as a local application. (Figure 1.15)

Operation
                                                            Figure 1.15

Delete record of any one employee and then click the Delete as in the figure 1.11:

Click Delete link and then confirm message in delete record as in the following figure 1.16,

Click delete link
                                                                  Figure 1.16

The data after delete record (Figure 1.17),

Data after delete Record
                                                      Figure 1.17


Note: If you have any question, then please mention in the comments section.