Please see my other MVC article.
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.
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.
When the default (Index) View is loaded for the Test Controller, the form prepopulated with current user’s record.