Click here to Skip to main content
12,689,305 members (28,451 online)
Click here to Skip to main content
Add your own
alternative version

Stats

39.9K views
1 download
34 bookmarked
Posted

ASP.NET MVC-5 CRUD Application with drop down list

, 27 Aug 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
ASP.NET MVC 5 applications

Introduction:

This tutorial will teach you the basics of building an ASP.NET MVC 5 Web application using Visual Studio 2013. I'll show you step-by-step operations using simple screen shorts. So get ready for that journey.

You need to about ASP.NET, SQL Server 2008 R2 & Visual studio 2013.

  • Models: Classes that represent the data of the application and that use validation logic to enforce business rules for that data.
  • Views: Template files that your application uses to dynamically generate HTML responses.
  • Controllers: Classes that handle incoming browser requests, retrieve model data, and then specify view templates that return a response to the browser.

How MVC works?

Application process:

 

Now create the project

  1. Open visual studio 2013, select new project

 

 

  1. Select ASP.NET Web application & assign name MyMVCApp then just click ok.

 

 

  1. Then select MVC & just click ok buttons.

 

 

 

  1. Now right click into model then add then New Item

  1. Now select ADO.NET Entry Data Model and write the name “MyAppEDM” and just click Add button.

 

 

  1. Now select Generate from database then click next.

 

  1. Now click New connection.

 

 

 

  1. Now type user name and password if you use SQL server authentications & select your database for example dbMYDAT then test connection & just click ok button.

 

  1. Now click save entry connection settings and click next.

 

 

  1. Now select your desire table, views, Store procedure etc. & then click finished.

 

 

 

  1. Now create a controller & write it name “StuInfoController”. Before creating controller you have to build the application.

 

For this above error you need to rebuild the applications.

 

 

  1. Now in RouteConfig just rename the defaults controller "Home" to “StuInfo” controller.

 

 

  1. Now just run the application then you probably see the following screen.

 

 

  1. Now you can able to create new one.

 

 

 

Code:

 

Model:

public partial class stuInfo
   {
       [Required]
       public string ID { get; set; }
       [StringLength(20, ErrorMessage = "Max length 30 characters")]
       public string Name { get; set; }
       [Required]
       public string Dept { get; set; }
       [Required]
       public string Subject { get; set; }

       public virtual DeptInfo DeptInfo { get; set; }
       public virtual SubjectInfo SubjectInfo { get; set; }
   }

 

 

Web config:

<connectionStrings>
  <add name="dbMYDATAEntities" connectionString="metadata=res://*/Models.MyAppEDM.csdl|res://*/Models.MyAppEDM.ssdl|res://*/Models.MyAppEDM.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=IT-WS08\SQLEXPRESS;initial catalog=dbMYDATA;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

 

Table script:

Stuinfo:

USE [dbMYDATA]

GO


/****** Object:  Table [dbo].[stuInfo]    Script Date: 08/27/2014 12:06:16 ******/

SET ANSI_NULLS ON

GO


SET QUOTED_IDENTIFIER ON

GO


CREATE TABLE [dbo].[stuInfo](

      [ID] [nchar](10) NOT NULL,

      [Name] [nvarchar](max) NULL,

      [Dept] [nchar](10) NULL,

      [Subject] [nchar](10) NULL,

 CONSTRAINT [PK_stuInfo] 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] TEXTIMAGE_ON [PRIMARY]


GO


ALTER TABLE [dbo].[stuInfo]  WITH CHECK ADD  CONSTRAINT [FK_stuInfo_DeptInfo] FOREIGN KEY([Dept])

REFERENCES [dbo].[DeptInfo] ([ID])

GO


ALTER TABLE [dbo].[stuInfo] CHECK CONSTRAINT [FK_stuInfo_DeptInfo]

GO


ALTER TABLE [dbo].[stuInfo]  WITH CHECK ADD  CONSTRAINT [FK_stuInfo_SubjectInfo] FOREIGN KEY([Subject])

REFERENCES [dbo].[SubjectInfo] ([Id])

GO


ALTER TABLE [dbo].[stuInfo] CHECK CONSTRAINT [FK_stuInfo_SubjectInfo]

GO

 

DeptInfo:

USE [dbMYDATA]

GO


/****** Object:  Table [dbo].[DeptInfo]    Script Date: 08/27/2014 12:07:15 ******/

SET ANSI_NULLS ON

GO


SET QUOTED_IDENTIFIER ON

GO


CREATE TABLE [dbo].[DeptInfo](

      [ID] [nchar](10) NOT NULL,

      [Dept] [nvarchar](50) NULL,

 CONSTRAINT [PK_DeptInfo] 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

 

 

SubjectInfo:

USE [dbMYDATA]

GO


/****** Object:  Table [dbo].[SubjectInfo]    Script Date: 08/27/2014 12:07:59 ******/

SET ANSI_NULLS ON

GO


SET QUOTED_IDENTIFIER ON

GO


CREATE TABLE [dbo].[SubjectInfo](

      [Id] [nchar](10) NOT NULL,

      [Subject] [nvarchar](max) NULL,

 CONSTRAINT [PK_SubjectInfo] 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] TEXTIMAGE_ON [PRIMARY]


GO

 

Thanks you so much for your patience.

 

References:

http://www.asp.net/mvc

https://www.codeplex.com/

http://www.c-sharpcorner.com/

http://www.codeproject.com/

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

eBook: Programming ASP.NET MVC 5 A Problem Solution Approach

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author


You may also be interested in...

Pro
Pro

Comments and Discussions

 
Questioncode Pin
Member 128152106-Dec-16 6:34
memberMember 128152106-Dec-16 6:34 
QuestionCreate mvc 5 project with oracle and visual studio 2013 Pin
Veeramani P20-May-15 21:49
memberVeeramani P20-May-15 21:49 
Questionquestion... Pin
GreatOak14-May-15 8:29
memberGreatOak14-May-15 8:29 
QuestionVery Good Article Sir Pin
ajaykumar varanasi27-Feb-15 1:52
memberajaykumar varanasi27-Feb-15 1:52 
QuestionThe code download is still missing. Pin
pixelmeow19-Jan-15 8:50
professionalpixelmeow19-Jan-15 8:50 
QuestionMessage Automatically Removed Pin
4-Nov-14 22:31
memberMd. Ilyas Hasan Mamun4-Nov-14 22:31 
Questiongreat! Pin
Aunebakk29-Oct-14 3:28
memberAunebakk29-Oct-14 3:28 
GeneralMy vote of 5 Pin
Christian Amado12-Sep-14 4:37
professionalChristian Amado12-Sep-14 4:37 
GeneralModels?? Pin
Math08avan2-Sep-14 0:48
memberMath08avan2-Sep-14 0:48 
GeneralRe: Models?? Pin
R M Shahidul Islam Shahed3-Sep-14 1:12
professionalR M Shahidul Islam Shahed3-Sep-14 1:12 
QuestionCode? Pin
treesprite29-Aug-14 12:15
membertreesprite29-Aug-14 12:15 
QuestionVote of 5 Pin
Russell_Smith29-Aug-14 2:02
memberRussell_Smith29-Aug-14 2:02 
GeneralMy vote of 5 Pin
A I Sabuz27-Aug-14 21:04
memberA I Sabuz27-Aug-14 21:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170113.4 | Last Updated 28 Aug 2014
Article Copyright 2014 by R M Shahidul Islam Shahed
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid