简体   繁体   中英

ASP.NET Web App CORE: the HttpPost Edit Method in Controller not being called

When i redirect to the Edit.cshtml page, only the HttpGet seems to be working. The HttpPost is not working. Which means that when I make changes and click on the Edit button on the Edit form, the HttpPost Edit is supposed to be invoked to call the PUT API. But the HttpGet Edit is called instead... What have I done wrong?

    public async Task<IActionResult> Edit(int? id)
    {
        if (id == null)
        {
            return NotFound();
        }

        await ViewBags();

        HttpResponseMessage response = await GlobalVariables.WebApiClient.GetAsync("article/detail/" + id.ToString());
        if (response.IsSuccessStatusCode)
        {
            var authorTagArticle = new AuthorTagArticle();
            authorTagArticle = response.Content.ReadAsAsync<AuthorTagArticle>().Result;
            var articleForm = new ArticleForm();
            articleForm.ArticleId = authorTagArticle.Article.ArticleId;
            articleForm.ArticleTitle = authorTagArticle.Article.ArticleTitle;
            articleForm.ArticleContent = authorTagArticle.Article.ArticleContent;
            articleForm.CreatedOn = authorTagArticle.Article.CreatedOn;
            articleForm.ImagePath = authorTagArticle.Article.ImagePath;
            articleForm.AuthorIds = authorTagArticle.Author.Select(e => e.UserId).ToArray();
            articleForm.TagIds = authorTagArticle.Tag.Select(e => e.TagId).ToArray();

            return View(articleForm);
        }
        else
        {
            TempData["error"] = "Error - Unable to open Edit Article Menu";
            return RedirectToAction("Index", "Home");
        }
    }

Try to edit your code as following: <form asp-controller="{Your controller}" asp-action="Edit" method="post"><\/code>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM