This is a migrated thread and some comments may be shown as answers.

Persist Current Page on Paging on Telerik ASP.NET Core Razor Pages ListView

1 Answer 171 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Luke
Top achievements
Rank 1
Luke asked on 26 Jun 2020, 08:48 AM
@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
@Html.AntiForgeryToken()
 
<script type="text/x-kendo-tmpl" id="template">
            <a class="product CB" href="/de/Details/#:SEOLink#">
                <div class="H160 C">
                    #if (IsIMG == '1') { #
                    <img src="https://xxxxx.com/img/#:SEOLink#-150.jpg" alt="#:SEOLink#" />
                    # } #
                    #if (IsIMG == '0') { #
                    <div class="fxacce H160"><p>No Image Available</p></div>
                    # } #
                </div>
                <hr class="HRGld0" />
            </a>
</script>
 
@(Html.Kendo().ListView<TEST.Pages.Movies.BluRayModel>()
        .Name("listView")
        .TagName("div")
        .HtmlAttributes(new { style = "border: none;" })
        .DataSource(dataSource => dataSource
 
        .Ajax()
 
        .Read(r => r.Url(Model.GetRead).Data("forgeryToken"))
                .PageSize(30)
            )
 
        .ClientTemplateId("template")
                    .Pageable()
    )
 
<script>
    function forgeryToken() {
        return kendo.antiForgeryTokens();
    }
</script>

 

Standard List View, nothing special. In the template, there is an "a href" link which redirects the user to a details page for the item.

The user clicks on the item, which redirects them to the details page, this works well.

The problem is when the click the "back" button on the browser to get back to the list view, the paging starts at page 1 and not the page they were looking at (example: page 5)

How can I retain the current page value? I guess I need somehow to fetch the current page the user is looking at, and then store it in a session variable. Thanks for the guidance.

1 Answer, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 30 Jun 2020, 01:37 PM

Hi Luke,

It is correct that the current page of the widget has to be saved in a session variable or local storage of the browser. This is due to the fact that whenever the user is redirected to another page, the current one is destroyed along with all components and HTML. When the user returns, the components are initialized once again. 

What I can recommend is that you subscribe to the DataBound event of the grid and check for the session variable value. Redirect to a page with the help of the page method of the data source:

https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/methods/page

You might need to have to introduce a flag that would be used to redirect to a page only once. Otherwise, an infinite loop could be created. 

Let me know if additional details are needed.

 

Kind regards,
Tsvetomir
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
ListView
Asked by
Luke
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
Share this question
or