[英]Page does not load when pressing back on browser
I have a small project in asp.net core 3.我在asp.net core 3中有一个小项目。
In one of the razor page I have this:在其中一个剃刀页面中,我有这个:
<form method="post" enctype="multipart/form-data">
<table class="basic">
@for (int i = 0; i < Model.activeSlides.Count; i++)
{
<tr>
<td>
<a href="~/source/Slides/@Model.activeSlides[i].Filename">@Model.activeSlides[i].Filename</a>
</td>
<td>
<input type="submit" value="Move Up" asp-page-handler="MoveUp" asp-route-num="@i" />
<input type="submit" value="Move Down" asp-page-handler="MoveDown" asp-route-num="@i" />
<input type="submit" value="Archive" asp-page-handler="Archive" asp-route-num="@i" />
</td>
</tr>
}
</table>
...
</form>
So each of the buttons has their own OnPost function.所以每个按钮都有自己的 OnPost 功能。 Each of them modify an XML file and loads the same webpage.
他们每个人都修改一个 XML 文件并加载相同的网页。
public void OnPostMoveUp(string num)
{
...
}
public void OnPostMoveDown(string num)
{
...
}
public void OnPostArchive(string num)
{
...
}
I have noticed that when the buttons are used, they show the page handler and route in the URL.我注意到当使用按钮时,它们会在 URL 中显示页面处理程序和路由。 Eg
https://localhost:44342/screens/edit?num=2&handler=MoveUp
例如
https://localhost:44342/screens/edit?num=2&handler=MoveUp
The problem I am facing is after a button has been pressed, the user may select a hyperlink in the first column.我面临的问题是按下按钮后,用户可能会在第一列中选择一个超链接。 This is just an image, but the when the back button on the browser is pressed the page does not load.
这只是一个图像,但是当浏览器上的后退按钮被按下时页面不会加载。
PS I am not using MVC. PS我没有使用MVC。
I have fixed this by adding Response.Redirect("/screens/edit");
我通过添加
Response.Redirect("/screens/edit");
解决了这个问题Response.Redirect("/screens/edit");
at the end of all the OnPost methods.在所有 OnPost 方法的末尾。
This means the url params don't show therefore then clicking a link and choosing back on the browser now works.这意味着 url 参数不会显示,因此单击链接并在浏览器上选择返回现在可以工作了。
This also fixes refreshing the page so it doesn't submit the form again.这也修复了刷新页面的问题,因此它不会再次提交表单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.