© Eric Vogel 2021
E. VogelBeginning Entity Framework Core 5https://doi.org/10.1007/978-1-4842-6882-7_19

19. Deleting Data on the Web

Eric Vogel1  
(1)
Okemos, MI, USA
 

In this chapter, I will cover how to delete a person record and their associated address record by updating the generated Delete Razor page controller code. There will be no UI changes needed.

Generated Delete Razor Page View

First, let us look at the generated Delete Razor Page view in Pages ➤ Contacts ➤ Delete.cshtml. Your view should look like Listing 19-1.
@page
@model EFCore5WebApp.Pages.Contacts.DeleteModel
@{
    ViewData["Title"] = "Delete";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1>Delete</h1>
<h3>Are you sure you want to delete this?</h3>
<div>
    <h4>Person</h4>
    <hr />

Get Beginning Entity Framework Core 5: From Novice to Professional now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.