- Mastering Entity Framework Core 2.0
- Prabhakaran Anbazhagan
- 181字
- 2021-07-02 21:16:41
Edit controller action
The same changes that we discussed with respect to the SelectList collection must be made to the Edit action as well:
public async Task<IActionResult> Edit(int? id)
{
...
ViewData["BlogId"] = new SelectList(_context.Blog, "Id", "Url",
post.BlogId);
return View(post);
}
The following screenshot shows the URL mapped to the BlogId control, and as part of the exercise, kindly make changes to the BlogId label with the literal changes you made in the Creating controller action section:

Edit a post
The same change needs to be applied to the Post action of Edit as well:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id,
[Bind("Id,BlogId,Content,PublishedDateTime,Title")] Post post)
{
...
ViewData["BlogId"] = new SelectList(_context.Blog, "Id", "Url",
post.BlogId);
return View(post);
}
The changes were reflected in the updated item that was displayed on the screen:

List view with edited post
We have updated the references to the Blog ID with Blog URLs in the Post Edit (HTTP, Get, and Post) action. Let's update this on the remaining DELETE action.
推薦閱讀
- 零基礎搭建量化投資系統:以Python為工具
- 深入淺出Java虛擬機:JVM原理與實戰
- 動手玩轉Scratch3.0編程:人工智能科創教育指南
- 營銷數據科學:用R和Python進行預測分析的建模技術
- Mastering Linux Network Administration
- Spring Boot進階:原理、實戰與面試題分析
- 利用Python進行數據分析(原書第3版)
- Learning Vaadin 7(Second Edition)
- Mastering openFrameworks:Creative Coding Demystified
- Learning Modular Java Programming
- Appcelerator Titanium:Patterns and Best Practices
- C++17 By Example
- 3ds Max 2018從入門到精通
- Visual Basic語言程序設計上機指導與練習(第3版)
- Java面向對象程序設計教程