'How do you maintain the previous scroll position after post using asp.net core 3.1 MVC and razor views?

How do you maintain the previous scroll position after a post using asp.net core 3.1 MVC (web application) and razor views?

How do you do this across the site?

I saw this: ASP.NET MVC3 Razor - Maintain scroll position on postback - but those did not work for me.



Solution 1:[1]

Another way to do this is to submit the form with AJAX and, after a successful POST, call window.location.reload(); which will restore the scroll position.

function CreateItem() {
    var serializedForm = $('#formId').serialize();

    $.ajax({
        url: "item/create",
        type: "POST",
        data: serializedForm
    })
    .done(function () {
        window.location.reload();
    });
}

Solution 2:[2]

you can use paginated report then you need to groupe your data in the report, you could use the page break option in your group. This means when you save it to PDF each group will be on it's own page.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lukas
Solution 2 ant_sol