【问题标题】:POST URL is missing handler query string in Razor PageRazor 页面中的 POST URL 缺少处理程序查询字符串
【发布时间】:2018-12-11 08:00:20
【问题描述】:

我遇到了一个问题,我的表单提交 url 没有指向代码隐藏中的处理程序的查询字符串。结果,我收到了 400(错误请求)错误。

请求 URL 如下所示: http://localhost:60900/EventRename

当它应该看起来像这样时: http://localhost:60900/EventRename?handler=RenameEvent

这是.cshtml

<form asp-page-handler="RenameEvent" method="post">
    <div class="form-group">
        <label asp-for="RenameDataSource"></label>
        @Html.DropDownListFor(x => x.RenameDataSource, Model.DataSources, "-- select data source --")
    </div>
    <div class="form-group">
        <label asp-for="RenameTempEvent"></label>
        @Html.DropDownListFor(x => x.RenameTempEvent, Model.RenameTempEvents, "-- select event type --")
    </div>
    <div class="form-group">
        <label asp-for="NewName"></label>
        @Html.DropDownListFor(x => x.NewName, Model.EventTypes, "-- select event type --")
    </div>
    <div class="form-group">
        <button type="submit">Start Renaming</button>
    </div>
</form>

这可能是相关的,但我也注意到表单数据缺少“__RequestVerificationToken”,它应该默认包含在 Razor 页面中?

澄清一下,我不希望在 URL 中看到表单中的数据。我希望看到一个处理程序引用,因此 Razor Code Behind 知道在提交表单时要运行哪个方法。请参阅此部分:https://docs.microsoft.com/en-us/aspnet/core/razor-pages/#multiple-handlers-per-page the URL path that submits to OnPostJoinListAsync is http://localhost:5000/Customers/CreateFATH?handler=JoinList

【问题讨论】:

    标签: asp.net post razor asp.net-core razor-pages


    【解决方案1】:
    @using (Html.BeginForm(ActionName, ControllerName, new { handler = "value of your handler" }, FormMethod.Post))
    

    现在您可以提交表单,它会为您提供相同的值。

    【讨论】:

      【解决方案2】:

      如果您想查看 url 中的数据字符串,您的表单方法是 post 尝试使用 get。 https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_and_retrieving_form_data

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-02
      • 2021-03-14
      相关资源
      最近更新 更多