31 Creating form applications

 

This chapter covers

  • Using ASP.NET Core form features with Entity Framework Core to create, read, update, and delete data
  • Managing the use of related data in Entity Framework Core results

The previous chapters have focused on individual features that deal with one aspect of HTML forms, and it can sometimes be difficult to see how they fit together to perform common tasks. In this chapter, I go through the process of creating controllers, views, and Razor Pages that support an application with create, read, update, and delete (CRUD) functionality. There are no new features described in this chapter, and the objective is to demonstrate how features such as tag helpers, model binding, and model validation can be used in conjunction with Entity Framework Core.

31.1 Preparing for this chapter

This chapter uses the WebApp project from chapter 30. To prepare for this chapter, replace the contents of the HomeController.cs file in the Controllers folder with those shown in listing 31.1.

Tip

You can download the example project for this chapter—and for all the other chapters in this book—from https://github.com/manningbooks/pro-asp.net-core-7. See chapter 1 for how to get help if you have problems running the examples.

31.1.1 Dropping the database

31.1.2 Running the example application

31.2 Creating an MVC forms application

31.2.1 Preparing the view model and the view

31.2.2 Reading data

31.2.3 Creating data

31.2.4 Editing data

31.2.5 Deleting data

31.3 Creating a Razor Pages forms application

31.3.1 Creating common functionality

31.3.2 Defining pages for the CRUD operations

31.4 Creating new related data objects

31.4.1 Providing the related data in the same request

31.4.2 Breaking out to create new data

Summary