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

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.

主站蜘蛛池模板: 江津市| 武邑县| 镇沅| 开鲁县| 佳木斯市| 栖霞市| 万山特区| 木里| 普兰店市| 凤山县| 汝阳县| 湖南省| 赫章县| 石屏县| 甘泉县| 宜君县| 宜宾县| 伊宁县| 邮箱| 高阳县| 洛川县| 冷水江市| 滨州市| 库伦旗| 鲁甸县| 虎林市| 基隆市| 浦江县| 潞西市| 恩施市| 桃园市| 虞城县| 金秀| 巴东县| 芒康县| 清新县| 邢台县| 鄄城县| 泸水县| 武安市| 黑龙江省|