Home > Blockchain >  Asp.net Core Razor Pages, page handler not working
Asp.net Core Razor Pages, page handler not working

Time:03-15

Can't call page handler methods. in razor page

<a asp-page="/CreateNew">Link1</a>

<a asp-page="/CreateNew"  asp-page-handler="submit">Link1</a>

CreateNew.cshtml.cs:

    public IActionResult OnGet()
    {            
        return Page();
    }

    public IActionResult OnGetSubmit()
    {            
        return Page();
    }

CodePudding user response:

If you use a razor page, you must put your file in the pages folder

Instead of Views Folder and your link will be as follows

<a asp-page="/PersonalPage/CreateNew">Link1</a>

And the startup file should be configured as follows

public void ConfigureServices(IServiceCollection services)
{
  services.AddRazorPages();
}


 ........

app.UseEndpoints(endpoints =>
{
    endpoints.MapRazorPages();
});

enter image description here

  • Related