When calling a handler from cshtml page (using Razor project) why it is doing full page refresh by going to public void OnGet() method and then it go to public IActionResult OnPostExportCSV(int id)? I was thinking by callling the hadler ExportCSV it will directly goto call OnPostExportCSV(int id)
Also found out first character of hander must be between ‘A to Z’, as mine was ‘_ExportCSV’ it is invalid.
Expected to directly call the Handler like AJAX call, but by calling Handler it is calling _Layout – I want to just call a method on server side nothing else.
3
When calling a handler from cshtml page (using Razor project) why it is doing full page refresh by going to public void OnGet() method and then it go to public IActionResult OnPostExportCSV(int id)? I was thinking by callling the hadler ExportCSV it will directly goto call OnPostExportCSV(int id)
When calling a handler, a form POST request is sent to the server, and calls the OnPostExportCSV method. If OnPostExportCSV returns a file download, it typically does not trigger a page reload. The browser will handle the file download without refreshing the page. However, if the form submission leads to a page refresh due to browser behavior, then OnGet might be called.
OnGet
to initialize state needed for the page. OnPost
to handle form submissions.
The handler, specified by the asp-page-handler
attribute. When the button is selected, a form POST request is sent to the server. By convention, the name of the handler method is selected based on the value of the handler parameter according to the scheme OnPost[handler]Async
.
You can learn more details in this doc.
Expected to directly call the Handler like AJAX call, but by calling Handler it is calling _Layout – I want to just call a method on server side nothing else.
You can use the Ajax call to achieve this.
5