This is working :
@page
@model test0201.Pages.IndexModel
@{
}
<form method="post">
<button type="submit" class="btn btn-primary">Test</button>
</form>
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace test0201.Pages
{
public class IndexModel : PageModel
{
public void OnGet()
{
}
public async Task OnPost()
{
Console.WriteLine("testtesttest");
}
}
}
And this is Not :
<form method="post">
<button type="submit" asp-page-handler="RefreshReturns" class="btn btn-primary">Test</button>
</form>
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace test0201.Pages
{
public class IndexModel : PageModel
{
public void OnGet()
{
}
public async Task OnPostRefreshReturnsAsync()
{
Console.WriteLine("testtesttest");
}
}
}
Handler just not working. ChatGPT and Google didnt help. What i am missing here? First i thought my method not working, so i tried to test it and put just Console.Writeline.
This is working :
@page
@model test0201.Pages.IndexModel
@{
}
<form method="post">
<button type="submit" class="btn btn-primary">Test</button>
</form>
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace test0201.Pages
{
public class IndexModel : PageModel
{
public void OnGet()
{
}
public async Task OnPost()
{
Console.WriteLine("testtesttest");
}
}
}
And this is Not :
<form method="post">
<button type="submit" asp-page-handler="RefreshReturns" class="btn btn-primary">Test</button>
</form>
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace test0201.Pages
{
public class IndexModel : PageModel
{
public void OnGet()
{
}
public async Task OnPostRefreshReturnsAsync()
{
Console.WriteLine("testtesttest");
}
}
}
Handler just not working. ChatGPT and Google didnt help. What i am missing here? First i thought my method not working, so i tried to test it and put just Console.Writeline.
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
. Otherwise, you need to include this line in your razor page view. Also, you can try to debug to see the rendered HTML for<button type="submit" asp-page-handler="RefreshReturns" class="btn btn-primary">Test</button>
. And share it in the question. Thanks. – Yong Shun Commented Jan 5 at 0:44action
attribute with ANY non-empty value, the CSRF input would not get generated, resulting in a 400. Perhaps you have something like this in your actual code? – BenderBoy Commented Jan 6 at 14:54