CREATING INTERNET APPLICATION PROJECT & MVC USING DATA BASE FIRST APPROACH
In this we are going to
see about how to create a project in visual studio and the concept of mvc.
Here in this demo we
are creating internet application base project.
Step 1: Open the
Microsoft Visual Studio.
Go to File in that go
to new and select Project.
In new project select
Visual C# , In that select ASP.NET MVC 4
Web Application. After selecting the project type give the name of the project
and the desired location where you want to save your project and press ok. In
my case I am giving my project name as my first project.
After pressing ok a
page will appear for selecting template to which we want to run our project.
Here we are selecting
our template as Internet Application. Internet Application is a account
controller that uses forms and authentication. Our view engine will be Razor.
After pressing ok project is generated.
Now let us see about
MVC (MODEL VIEW CONTROLLER).
Model : It should be
responsible for the data of application domain.
View : It presents the
display of the model in the user
interface.
Controller : It is
really the heart of the MVC, the
intermediary that ties the Model and the View together, i.e. it takes the user
input, manipulate the model and causes view to update.
There are three fields
with which we are working with in ASP.NET:
1.
Model first approach
2.
Data Base first approach
3.
Code first approach
Now let us see about
Data Base first approach:
The Data Base first
approach provides an alternative to the Code first & Model first approaches to Entity Data
Model and it creates Model Codes (Classes, Properties, Db context etc) from the
database in the project and those classes become the link between the database
and controller.
Now let us see how to
connect with the database. In the Visual Studio window go to Solution Explorer
in solution explorer go to Model right click on the model and click add a drop
down window will appear in that go to new item and press it as shown in the
below figure.
After pressing new item a window will appear
in that select ADO.NET Entity Data Model and press add
After pressing add
choose model content as Generate From Data Base as shown in the below figure.
Press next after
selectiong model content a window will appear asking for name of connection to
connect with database.
Press new connection A
window will appear asking for server name and database name, press the server
name and the database name which you have created in your sql server. My
database name is management as I have created a database with name as
management.
After pressing ok a
connection with entity connection string is generated.
Press next a window
will appear asking for database objects to be included in the model I am
selecting tables to be included in my model.
Press finish out table
from the database is added.
Go to HomeController.cs
in that go to Public ActionResult and give a name to it I am giving action
result name as employee.
After that rightclick on the action view and press
add view
Go to use a layout or
master page and select Shared from the project folder and Cshtml from the
content folder as shown in below figure.
Press ok a page will be
generated in that page insert Html code.
After putting the html
code press run button, to run the code.
Local host will be
generated in that give the controller name .






















Comments
Post a Comment