- 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.
推薦閱讀
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- 小程序實戰視頻課:微信小程序開發全案精講
- Docker進階與實戰
- 大學計算機基礎實驗教程
- Mastering Selenium WebDriver
- Flink SQL與DataStream入門、進階與實戰
- TestNG Beginner's Guide
- Learning Bayesian Models with R
- 精通Python設計模式(第2版)
- Swift語言實戰精講
- Mastering React
- Julia for Data Science
- Visual Basic程序設計習題與上機實踐
- Buildbox 2.x Game Development
- Vue.js光速入門及企業項目開發實戰