【发布时间】:2020-01-17 12:27:55
【问题描述】:
我正在尝试(非 Ajax)获取一个复选框以在 Razor 页面中重新提交表单并重新加载页面 / 并在我的 OnPost 方法中捕获结果。
我的 index.cshtml 中有
@page "{id:int?}"
@model IndexModel
<div class="text-center">
<form action="post" name="form1">
<strong>Filter:</strong> Hide Single Runs <input onclick="document.form1.submit()" asp-for="@Model.HideSingle" />
<hr />
在我的 PageModel 中
public class IndexModel : PageModel
{
public bool HideSingle { get; set; } = true;
public async Task OnPost(int? id, bool hideSingle)
{
说一个起始页的 URL:
http://localhost:5000/TestRuns/1
表单在复选框单击时提交,但它以一个 Url 结尾:
http://localhost:5000/TestRuns/post?HideSingle=false
这显然无法解决,因为我期待http://localhost:5000/TestRuns/1 的路线。
【问题讨论】: