ASP Razor pages - async and update page

Filippo 41 Reputation points
2022-12-09T09:05:34.243+00:00

Hello

i'm new to asp Razor pages, i'm trying to build an app that aska server (external server not blazor) some data in XML.
All ok, until i try to wait for results and update the page.
after this method, how to update the page ? Do you have anylink to refer to?:

public async void OnPostQueryOpening (string Id, string FormType, string OpeningName)
{
LoadOpenings("");
await Calcola(Id, FormType);

        HERE : HOW TO UPDATE THE PAGE WITHOUT LOOSING DATA?  
    }
Developer technologies ASP.NET ASP.NET Core
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2022-12-12T07:17:59.837+00:00

    Hi @Filippo ,

    First, by default, if you are using the Submit Form method to call this handler method, it will wait for the async method execute, and then if you are using BindProperty and tag helper to bind the property, it will update the data in current page.

    Besides, you can change the handler method and return the updated data, then try to use JQuery Ajax to call the handler method, then return the data to the view page and update the page. Refer to the following code:

    .cshtml:

    269584-image.png

    .cshtml.cs:

    269566-image.png

    In the Program.cs file, configure the Antiforgery token.

    builder.Services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");  
    

    Then, the result as below:

    269612-image1.gif

    In the Handler method, if you want to store the data, you can try to use session or database.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.