I have a Razor Page template with an HTML form. I wish to trigger a specific method on the post event.
The form is as follows:
<form method="post" asp-page-handler="Edit">
<input type="text" name="firstName" />
<input type="submit" value="Submit" />
</form>
And the page model:public class TestPageModel : RazorPageModel<TestPage>
{
...
public void OnPostEdit(string firstName)
{
var s = firstName;
}
}
According to ASP .NET Core documentation and handler naming conventions, asp-page-handler="Edit"
should trigger the OnPostEdit
method.
If I add the general OnPost
method, it will be triggered on the form submit:
public void OnPost(string firstName)
{
OnGet();
}
But I have several forms on the page template, and each needs its own method.
I cannot find any Optimizely documentation regarding this, and I suspect the issue is due to Optimizely routing.
Has anybody solved this?