- 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.
推薦閱讀
- TensorFlow Lite移動端深度學習
- C語言程序設(shè)計基礎(chǔ)與實驗指導
- Production Ready OpenStack:Recipes for Successful Environments
- Visual Basic學習手冊
- Apache Mahout Clustering Designs
- Getting Started with Laravel 4
- Getting Started with Hazelcast(Second Edition)
- Mastering ROS for Robotics Programming
- Visual Studio 2015高級編程(第6版)
- Instant Debian:Build a Web Server
- 零基礎(chǔ)學HTML+CSS
- Visual Basic語言程序設(shè)計上機指導與練習(第3版)
- Android應用開發(fā)攻略
- ANSYS FLUENT 16.0超級學習手冊
- Socket.IO Cookbook