- Mastering Entity Framework Core 2.0
- Prabhakaran Anbazhagan
- 238字
- 2021-07-02 21:16:41
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 select Add | New Scaffolded Item.
- Add Scaffold dialog box, select MVC Controller with views, using Entity Framework:

- In the Add Controller dialog box, select the appropriate Model class and Data Context class (Post and MasteringEFCoreDbFirstContext in our case) along with the auto-generated controller name, PostsController:

- Next click Add as shown in the following screenshot:

Scaffolded items
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>
...
<td>
//@Html.DisplayFor(modelItem => item.Blog.Id)
@Html.DisplayFor(modelItem => item.Blog.Url)
</td>
</tr>
}
The changes are reflected on the screen, where we can see Blog URLs rendered instead of the IDs that were listed before:

Posts list view
We have scaffolded CRUD operations and modified Blog ID usage to URLs in the Post index action. Let's update the same on the other actions as well.
- Python程序設計教程(第2版)
- LabVIEW程序設計基礎與應用
- Pandas Cookbook
- 數(shù)據(jù)庫系統(tǒng)原理及MySQL應用教程
- KnockoutJS Starter
- TypeScript項目開發(fā)實戰(zhàn)
- ArcGIS By Example
- PHP編程基礎與實例教程
- 從Excel到Python數(shù)據(jù)分析:Pandas、xlwings、openpyxl、Matplotlib的交互與應用
- 你真的會寫代碼嗎
- 虛擬現(xiàn)實建模與編程(SketchUp+OSG開發(fā)技術)
- LabVIEW入門與實戰(zhàn)開發(fā)100例(第4版)
- Java Web入門很輕松(微課超值版)
- 大象:Thinking in UML(第二版)
- Visual C++ 開發(fā)從入門到精通