Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
After completing the update, I am trying to inform it with a warning message and redirect it to another page. It does not redirect after receiving the notification message.

[HttpPost("Home/Edit/{id}")]
   [ValidateAntiForgeryToken]
   public ActionResult Edit(int id, IFormCollection collection)
   {
       try
       {
          /*bla bla bla*/
           Response.WriteAsync($"<script language=javascript>alert('successfully updated');</script>");
           return RedirectToAction(nameof(List));
       }
       catch
       {
           return View();
       }
   }


What I have tried:

I deleted Response.WriteAsync and its worked but this code necessary for alert
Posted
Updated 4-Jul-21 23:01pm

 
Share this answer
 
A redirect response returns an HTTP status code of 3xx along with a header telling the browser which URL should be requested.

You cannot combine that with a response body that shows an alert message.

If you want to show an alert before redirecting, you'll need to use script to redirect:
C#
// blah blah
return View("AlertAndRedirect");
AlertAndRedirect.cshtml
Razor
<script>
alert("successfully updated");
location.assign('@Url.Action("List")');
</script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900