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

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.

主站蜘蛛池模板: 龙山县| 灵川县| 山阴县| 武山县| 托克逊县| 镇安县| 兴安县| 肥乡县| 原平市| 武安市| 大同市| 永城市| 双柏县| 加查县| 聂荣县| 桂东县| 乳山市| 根河市| 旬邑县| 阜南县| 托里县| 佳木斯市| 治多县| 凌源市| 聂拉木县| 壶关县| 台中市| 随州市| 牡丹江市| 广东省| 乳源| 尉氏县| 合阳县| 大名县| 谷城县| 涿鹿县| 漳浦县| 安西县| 杭锦旗| 建昌县| 界首市|