首页 > 解决方案 > 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
}

我的错是什么?根据文档,它应该是一个非常基本的程序。

标签: razor-pages

解决方案


自定义处理程序的名称存在问题:如果名称以非大写字母开头,则剃须刀页面的处理程序机制无法识别名称。即永远不会使用 OnPostcustom,而 OnPostCustom 会成功


推荐阅读