I have been trying to figure this one out for days now and not having much luck at all.
We have a “details” @Html.ActionLink in a foreach loop in a Datatable.
Then in an “Outcomes” controller we have the HTTPGet and HTTPPost action to populate this datatable.
Outcomes controller code listed here…. https://localhost:5003/Outcomes/ByProcedure
[HttpGet]
public IActionResult ByProcedure()
{
…code to get result list
return View(result);
}
[HttpPost]
public IActionResult ByProcedure(IFormCollection form, string submitForm)
{
…after clicking submit button we take form input date pickers for start and end dates and pass in to get list
return View(result);
}
When I click the details link it goes to a different “Reports” controller and action seen below
<tr>
<td class="detailslink">@Html.ActionLink("Details", "ByProcedureDetailView", "Reports", new { @id = item.ProcTypeID }, null)</td>
</tr>
Here is the action result in the “Reports” controller have the action: https://localhost:5003/reports/ByProcedureDetailView/7
[HttpGet]
public IActionResult ByProcedureDetailView()
{
code to load another datatable…
return View(result);
}
The datatable populates fine in this page.
However, the issue is if we click the back button from this page
https://localhost:5003/reports/ByProcedureDetailView/7
To this page:
https://localhost:5003/Outcomes/ByProcedure
We get the below message and see this in the Dev Tools after clicking the back button.
This happens in Chrome, Safari and IE etc.
Confirm Form Resubmission
This webpage requires data that you entered earlier in order to be properly displayed. You can send this data again, but by doing so you will repeat any action this page previously performed.
* Press the reload button to resubmit the data needed to load the page.
ERR_CACHE_MISS
I have looked all over the internet and not finding really anything helpful.
Any help would be greatly appreciated.
This is the behavior of the browser.
If the submission page is a shopping cart checkout page, and repost detection was not on the server, then the user will be charged twice. This is a very common problem, and the browser must detect this and warn the user.
Usually we use PRG pattern to solve this problem, or use TempData
.
You can refer to this.
In your case, you can combine the above two methods to solve it.
I have created a simple demo you can refer as follow:
[HttpGet]
public IActionResult ByProcedure()
{
var result = _context.Cobro.ToList();
var value = TempData["Cobro"];
if (value is string json)
{
result = JsonConvert.DeserializeObject<List<Cobro>>(json);
}
return View(result);
}
[HttpPost]
public IActionResult ByProcedure(IFormCollection form, string submitForm)
{
var result = _context.Cobro.ToList().Where(x => x.Telefono == submitForm).ToList();
TempData["Cobro"] = JsonConvert.SerializeObject(result);
TempData["Name"] = submitForm;
return RedirectToAction(nameof(ByProcedure));
}
View:
@model IEnumerable<WebApplication_core_mvc.Models.Cobro>
@{
ViewData["Title"] = "ByProcedure";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1>ByProcedure</h1>
<form asp-action="ByProcedure">
<input id="Text1" type="text" name="submitForm" value="@TempData["Name"]"/>
<table class="table table-bordered">
<tr>
<th>Telefono</th>
<th>Empresa</th>
<th>Saldo</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.Telefono</td>
<td>@item.Empresa</td>
<td>@item.Saldo</td>
<td class="detailslink">@Html.ActionLink("Details", "ByProcedureDetailView", "Reports", new { @id = item.Presta }, null)</td>
</tr>
}
</table>
<input id="Submit1" type="submit" value="submit" />
</form>