官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 青川县| 九寨沟县| 大田县| 故城县| 黄龙县| 永胜县| 额尔古纳市| 大英县| 赤城县| 榆林市| 喀喇| 华蓥市| 巫山县| 定南县| 靖安县| 阿勒泰市| 尤溪县| 伊金霍洛旗| 中超| 美姑县| 同仁县| 襄城县| 奈曼旗| 石泉县| 武穴市| 志丹县| 永善县| 天柱县| 安义县| 滦南县| 威海市| 新津县| 肥城市| 全州县| 清徐县| 浏阳市| 青神县| 三穗县| 安康市| 东阳市| 班戈县|