razor-pages - Razor Pages asp-page-handler OnPostcustom 未触发
问题描述
我编写了 asp.net razor pages 网络应用程序。在页面/表单上,我想在发布期间区分的控件很少。不幸的是,我未能定义自定义处理程序,它总是通过默认的 OnPost 触发。
在页面上:
<form method="post">
<button type="submit" class="btn btn-default" asp-route-data="2" asp-page-handler="custom">Start test 2</button>
</form>
在模块中:
public void OnPost()
{
ViewData["confirmation"] = $"from OnPost";
}
public void OnPostcustom(string data)
{
ViewData["confirmation"] = $"from OnPostcustom";//never reach this line
}
我的错是什么?根据文档,它应该是一个非常基本的程序。
解决方案
自定义处理程序的名称存在问题:如果名称以非大写字母开头,则剃须刀页面的处理程序机制无法识别名称。即永远不会使用 OnPostcustom,而 OnPostCustom 会成功
推荐阅读
- c# - C# - 如何使用 C# 在整个 Excel 文件中取消选择换行
- powershell - Exchange Powershell 循环分发列表
- python - 提取文件名 python 的一部分并插入 MySQL DB
- audio-streaming - 将原始音频数据从服务器流式传输到客户端
- nativescript - Nativescript RadDataForm - 从后面的代码中提供 valuesProvider
- android - variant.getJavaCompiler()、variant.getJavaCompileProvider()、variantOutput.getPackageLibrary()、variant.getPackageLibraryProvider() 中的警告
- angular - 已修复:Angular 9:使用 Angular 功能的未修饰基类
- ruby-on-rails - 是什么导致 bin/rails:与非类/模块(TypeError)相比?
- r - 在 R 中查找正则表达式调用以仅返回名字和姓氏或完整的团队名称
- java - 如何在多逗号行中使用逗号分隔字符串