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

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.

主站蜘蛛池模板: 桐城市| 泰宁县| 广昌县| 西华县| 邳州市| 荔浦县| 营山县| 宁夏| 灵璧县| 唐河县| 沂南县| 苏州市| 房山区| 四会市| 武乡县| 巴彦县| 新兴县| 安岳县| 东平县| 株洲县| 瑞昌市| 钦州市| 南靖县| 盱眙县| 镇原县| 云南省| 钟祥市| 吕梁市| 龙陵县| 平山县| 中宁县| 工布江达县| 江都市| 革吉县| 望谟县| 如皋市| 建水县| 莱州市| 新巴尔虎右旗| 孟村| 阿克|