Sunday, January 11, 2015

CRUD Operation in MVC 4 part 1



In this article series I am going to describe about Insert, update, delete operation in MVC by simple method using store Procedure.  So Let us first of all database schema, here I want to do insert, update delete operation on employee Record. So I have to create Table Employee
USE [Pulkit]
GO

/****** Object:  Table [dbo].[EmployeeDetails]     ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[EmployeeDetails](
      [id] [int] IDENTITY(1,1) NOT NULL,
      [Name] [nvarchar](50) NOT NULL,
      [salary] [int] NOT NULL,
      [Department_id] [int] NOT NULL,
 CONSTRAINT [PK_EmployeeDetails] PRIMARY KEY CLUSTERED
(
      [id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO


Note : Since EmployeeDetails Table Have field Department_id.So here create another table department.


USE [Pulkit]
GO

/****** Object:  Table [dbo].[DepartmentDetails]    ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[DepartmentDetails](
      [Department_id] [int] IDENTITY(1,1) NOT NULL,
      [Department_Name] [nvarchar](50) NOT NULL,
      [Department_Locatiom] [nvarchar](50) NOT NULL
) ON [PRIMARY]

GO



Now I have insert some record in both EmployeeDetails and DepartmentDetails Table.




Now open Visual Studio 2012 And Create A New MVC application BY   Click On

Step 1

Start => Visual Studio 2012 => File => New File => Project =>Web => Asp.Net MVC4 web Application.
=> define the name and location of project=> OK



Step 2
Now a new window will be open where you have to select Internet Application Under Project Template and Razor As a View Engine.


Step 3
Click Ok
Note:-  your Mvc4 project will create successfully.  



You can see within solution explorer your project contain Several different folder for different purpose. For example Model, View, Controller, Script, Content etc.
Model:  Model is nothing it can be entity or business object. We can create it within Model folder OR MY own separate folder also.
View:  The purpose of View to Render the Data Format the data and present to the End user. In simpler term (It collect the data and display the data nothings else)
Controller:  Controller is nothing only a class that inherits from base controller class and contains the method which is known as (Action method).

Note: Controller Responds to the url request, get data from a model and hands it over to the view. View than render data.




CRUD Operation in MVC 4 part 3

 

                                             Author- Sayta Prakash

1 comment: