Thursday, 13 October 2016

MVC Complete Project With Code

Creating Cascading DropDownList In MVC 5 Using Entity Framework 6.0 Database First Step By Step 


step 1:

Create database first 
 Create database cascadingcountrystatecity;
USE [cascadingcountrystatecity]
GO
/****** Object:  Table [dbo].[C_State]    Script Date: 10/13/16 3:27:34 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[C_State](
[StId] [int] IDENTITY(1,1) NOT NULL,
[ConId] [int] NULL,
[StName] [nvarchar](100) NULL,
[DateTimeStamp] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED 
(
[StId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED 
(
[StName] 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
/****** Object:  Table [dbo].[City]    Script Date: 10/13/16 3:27:34 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[City](
[CityId] [int] IDENTITY(1,1) NOT NULL,
[Stid] [int] NULL,
[CityName] [nvarchar](100) NULL,
[DateTimeStamp] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED 
(
[CityId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED 
(
[CityName] 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
/****** Object:  Table [dbo].[country]    Script Date: 10/13/16 3:27:34 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[country](
[ConId] [int] IDENTITY(1,1) NOT NULL,
[ConName] [nvarchar](100) NULL,
[DateTimeStamp] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED 
(
[ConId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
UNIQUE NONCLUSTERED 
(
[ConName] 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
/****** Object:  Table [dbo].[employee]    Script Date: 10/13/16 3:27:34 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[employee](
[Empid] [int] IDENTITY(1,1) NOT NULL,
[EmpName] [nvarchar](100) NULL,
[ConId] [int] NULL,
[StId] [int] NULL,
[CityId] [int] NULL,
PRIMARY KEY CLUSTERED 
(
[Empid] 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
ALTER TABLE [dbo].[C_State] ADD  DEFAULT (getdate()) FOR [DateTimeStamp]
GO
ALTER TABLE [dbo].[City] ADD  DEFAULT (getdate()) FOR [DateTimeStamp]
GO
ALTER TABLE [dbo].[country] ADD  DEFAULT (getdate()) FOR [DateTimeStamp]
GO
ALTER TABLE [dbo].[C_State]  WITH CHECK ADD FOREIGN KEY([ConId])
REFERENCES [dbo].[country] ([ConId])
GO
ALTER TABLE [dbo].[City]  WITH CHECK ADD FOREIGN KEY([Stid])
REFERENCES [dbo].[C_State] ([StId])
GO
ALTER TABLE [dbo].[employee]  WITH CHECK ADD FOREIGN KEY([CityId])
REFERENCES [dbo].[City] ([CityId])
GO
ALTER TABLE [dbo].[employee]  WITH CHECK ADD FOREIGN KEY([ConId])
REFERENCES [dbo].[country] ([ConId])
GO
ALTER TABLE [dbo].[employee]  WITH CHECK ADD FOREIGN KEY([StId])
REFERENCES [dbo].[C_State] ([StId])
GO
USE [master]
GO
ALTER DATABASE [cascadingcountrystatecity] SET  READ_WRITE 
GO



1: Select and copy Above Script 
2: Open sql server management studio 
3: open query window 
4: paste and execute above query :


Step 2:

1: Open visual studio 2013 and above 
2: Create web application with mvc 
3: Right click on models folder 

coming soon