To bring it all together, let's make use of Visual Studio's built-in code generation features to take advantage of scaffolding and binding. In this section, we will cover field attributes that assist in model validation.
Before we wrap up this chapter, we will also learn about the use exception handling to catch errors in your code.
Using the PatientRecords
project we've built so far, let's add a new controller to it following the following steps, to make use of scaffolding. Instead of clicking on Add Item, we will choose the Controller option:
In Solution Explorer, right-click the
Controllers
folder.In the context menu, click Add | Controller.
Select the option to add a new MVC controller with views, using EF.
You will be prompted for additional information while adding your controller. Select/enter the following information:
Model class:
Human
, from your models namespaceData context class:
ApplicationDbContext
Controller name...