3
votes

I wrote asp.net razor pages web app. On the page/form there are few controls that I want to distinct during the post. Unfortunatly I failed to define custom handler, its always fired thruogh the default OnPost .

on the page:

<form method="post">
    <button type="submit" class="btn btn-default" asp-route-data="2" asp-page-handler="custom">Start test 2</button>
</form>

in the module:

public void OnPost()
{
    ViewData["confirmation"] = $"from OnPost";
}

public void OnPostcustom(string data)
{
     ViewData["confirmation"] = $"from OnPostcustom";//never reach this line
}

what is my fault? according to the documentation it should be a very basic procedure.

1

1 Answers

3
votes

There is a problem with the name of custom handler: handler mechanism of razor pages doesn't recognize the name if it starts with a not capital letter. i.e OnPostcustom will never be used, while OnPostCustom will succeed