【发布时间】: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