I created a brand new ASP .NET Core Razor web application and when I post with a custom asp-page-handler, OnPost() is hit, not OnPostContact(). This is such a simple form so there must be something simple I have overlooked.
Definitely a problem with my taghelpers, as I can get a model value to display like this:
@Model.FirstName
But not like this:
<input asp-for="FirstName" type="text" class="form-control" />
Here's the code, I can't see what's wrong here:
Index.cshmtl:
<form method="post" asp-page-handler="Contact">
@Html.AntiForgeryToken()
<div asp-validation-summary="ModelOnly"></div>
<span asp-validation-for="FirstName"></span>
<input type="text" asp-for="FirstName" />
<button type="submit">Send</button>
</form>
Index.cshtml.cs:
public IActionResult OnPost()
{
return Page();
}
public IActionResult OnPostContact()
{
return Page();
}
_ViewImports.cshtml:
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@Html.AntiForgeryToken, it is added automatically. And I do putasp-page-handler="Contact"inside submit button tags and it works fine. - LazZiya