Performing CRUD operations
We have already seen how to create CRUD operations right from scaffolding controllers to their corresponding views for the Blog
model, so we will create them for the Post
model in this section:
- Right-click on the
Controllers
folder and selectAdd
|New Scaffolded Item.
-
Add Scaffold
dialog box, selectMVC Controller with views, using Entity Framework
:
- In the
Add Controller
dialog box, select the appropriateModel class
andData Context
class (Post
andMasteringEFCoreDbFirstContext
in our case) along with the auto-generated controller name,PostsController
:
- Next click Add as shown in the following screenshot:
Scaffolded items
Note
The Blog URL should be displayed instead of the Blog ID, which was part of the scaffolding. As displaying the ID raises security issues and usability concerns, let's change this mapping to URL.
Let's start our changes from the Index.cshml
file, where we have listed Blog.Id
instead of Blog.Url
:
@foreach (var item in Model) { <tr>...