MVC: Displaying Data Source Records

Please see my other MVC articles.

Leveraging the Data Model to Retrieve Records for Display.

As illustrated in MVC 4 ADO.NET Entity Data Model, Visual Studio now provides an extremely efficient ORM tool to quickly generate the data layer for CRUD operations.
In this article, I will illustrate how to query and display data from the database into an Html form’s controls.
The following form displays three simple model fields for input by the user.

1-MVC-4-Displaying Datasource Records

However, I want the current record to prepopulate the form for the user to update so I will update the Index() ActionResult with some logic to retrieve a record, populate the model, and pass that model onto the View.

2-MVC-4-Displaying-Datasource-Records

3-MVC-4-Accessing-Form-Values

When the default (Index) View is loaded for the Test Controller, the form prepopulated with current user’s record.

4-MVC-4-Accessing-Form-Values

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s