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

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.

主站蜘蛛池模板: 三都| 雷州市| 防城港市| 赤峰市| 临湘市| 陇川县| 南江县| 永清县| 琼海市| 咸丰县| 赤水市| 马龙县| 启东市| 阿拉善左旗| 巴南区| 芦溪县| 汾西县| 睢宁县| 宁强县| 南丹县| 荃湾区| 化德县| 云霄县| 兴和县| 喜德县| 冀州市| 千阳县| 宜州市| 海安县| 漠河县| 蓬莱市| 沽源县| 高青县| 金山区| 博白县| 阿拉善左旗| 桦川县| 明光市| 息烽县| 曲麻莱县| 车致|