Friday, September 19, 2014

Getting Started With ASP NET MVC 4 Part 5 (Accessing Your Model's Data from a Controller)

---
Getting Started With ASP NET MVC 4 Part 5 (Accessing Your Model's Data from a Controller)
STEPS
1) Open your MvcMovie solution
2) Build the application
3) Add New Controller
3-1) Right-click Controllers, select Add/Controller…
3-2) Set Controller options
3-3) The IDE automatically generated the following files (SCAFFOLDING)
4) Test Run.
4-1) Press F5 Key.
4-2) Append “Movies” after the default URL.
4-3) Click Create New link
4-4) Try adding a new record
4-5) The new record has been successfully added to the database
4-6) Check the database

STEPS

1) Open your MvcMovie solution

2) Build the application

Info:
Building Solution instructs the IDE to compile codes especially the Model classes added in the previous tutorial so that the class would be recognized in the next step.

3) Add New Controller

3-1) Right-click Controllers, select Add/Controller…

3-2) Set Controller options

Controller name: MoviesController. (This is the default. )
Template: MVC Controller with read/write actions and views, using Entity Framework.
Model class: Movie (MvcMovie.Models).
Data context class: MovieDBContext (MvcMovie.Models).
Views: Razor (CSHTML). (The default.)

3-3) The IDE automatically generated the following files (SCAFFOLDING)

The IDE generates the controller file together with its associated view files.

4) Test Run.

4-1) Press F5 Key.

4-2) Append “Movies” after the default URL.

4-3) Click Create New link

4-4) Try adding a new record

4-5) The new record has been successfully added to the database

4-6) Check the database

Stop project execution.
In Solution Explorer, select the App_Data folder and click Show All Files.
When the data file is shown, double-click the item. You will be switched to Server Explorer.
Explode the movies table, right-click the item and select Show Table Data.
The table content is displayed in the main window.
---


No comments:

Post a Comment