November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
Perhaps not by-the-book, by you can simply add ?handler=edit to the form action URL if you're posting to the current page:
Example:
@using (Html.BeginForm(FormMethod.Post, new { action = "?handler=edit" }))
{
<button type="submit">Invoke OnPostEdit()</button>
}
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 theOnPostEdit
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?