Razor Pages 中多个冲突的路由参数格式

Multiple conflicting route parameter formats in Razor Pages

我正在根据 Razor Pages MVVM 教程制作简单的 crud 表单 - https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/?view=aspnetcore-2.1

问题是索引页面上的元素使用不同的路由参数格式,我最终得到 URL 之类的 /StockIndexMonths/2?StockIndexId=1 其中 /2 和 StockIndexId=1 是相同的参数

谁能告诉我强制使用相同参数格式的首选方法?我正在努力让 Razor Pages 保持 'magic'

Index.cshtml

@page "{StockIndexId?}"
@model Investments.Pages.StockIndexMonths.IndexModel
@{
    ViewData["Title"] = "Index";
}

<h2>Index</h2>

<form>
    <select asp-for="StockIndexId" asp-items="Model.StockIndexNameSelect" onchange="this.form.submit();"></select>
</form>

    <a asp-page="Create" asp-route-StockIndexId="@Model.StockIndexId">Create New</a>

<table class="table">
...

更改表单标签,使其使用 POST 方法:

<form method="post">

目前,由于未指定method,默认使用GET,将表单值附加到URL作为查询字符串值。这就是为什么你看到你所看到的。