New to Telerik UI for ASP.NET MVCStart a free 30-day trial

ASP.NET MVC ScrollView Overview

The Telerik UI ScrollView HtmlHelper for ASP.NET MVC is a server-side wrapper for the Kendo UI ScrollView widget.

The ScrollView displays a horizontal collection of content or image views with built-in navigation between them. It can be scrolled through dragging, gestures, arrow click or page click or tap. Among the key features of the ScrollView are data-source binding, customizable template, built-in pager, adjustable bounce effects and scroll velocity.

Initializing the ScrollView

You can initialize the ScrollView either from HTML or from a data source with a template.

From HTML

  1. Use its Items() method.
  2. Add HTML elements for each page as part of the content of the ScrollView items.
Razor
    <style>
        h1 {
            margin-top: 30%;
            text-align:center;
        }
    </style>
    @(Html.Kendo().ScrollView()
            .Name("scrollView")
            .ContentHeight("100%")
            .Items(x =>
            {
                x.Add().Content("<h1>One</h1>");
                x.Add().Content("<h1>Two</h1>");
                x.Add().Content("<h1>Three</h1>");
            })
            .HtmlAttributes(new { style = "height:748px; width:1022px; max-width: 100%;" })
    )

From the Data Source

  1. Create a Kendo UI for jQuery template.
  2. Use the TemplateId() method to pass it and provide a DataSource.

Make sure that the template provides the pageSize of the data source. If serverPaging is enabled, the ScrollView will request the data in advance so it becomes available before it is required, thus improving user experience. The ScrollView uses virtualization when it is bound to a data source and it only has three pages at all times—the current, the previous, and the next.

Razor
    @(Html.Kendo().ScrollView()
         .Name("scrollView")
         .ContentHeight("100%")
         .TemplateId("employee-template")
         .DataSource(d =>
                d.Custom()
                  .Type("odata")
                  .Transport(t => t.Read(r => r.Url("https://demos.telerik.com/kendo-ui/service/Northwind.svc/Employees")))
                  .ServerPaging(true)
                  .PageSize(1))
         .HtmlAttributes(new { style = "height:600px; width:890px; max-width: 100%;" })
    )
    <script id="employee-template" type="text/x-kendo-template">
        <div class="template">
            <h1>
                <span>#:TitleOfCourtesy# #: FirstName# #: LastName# </span>
            </h1>
            <h3>Title: #: Title #</h3>
            <div class="notes"><em>#:Notes#</em></div>
            <div class="country">
                #: Country #
            </div>
        </div>
    </script>

The following example demonstrates how to fetch data from a Controller action.

Razor
    @(Html.Kendo().ScrollView()
        .Name("scrollView")
        .EnablePager(false)
        .ContentHeight("100%")
        .TemplateId("scrollview-template")
        .DataSource(dataSource => dataSource
            .Custom()
            .Type("aspnetmvc-ajax")
            .Transport(transport => transport
            .Read(read => read.Action("GetScrollViewData", "Home"))
            )
            .Schema(s => s.Data("Data").Total("Total"))
            .ServerPaging(true)
            .PageSize(1))
        .HtmlAttributes(new { style = "height:200px; width:300px" })
    )

    <script id="scrollview-template" type="text/x-kendo-template">
        <p style="border: 2px solid blue; color: red;">#= data.SomeField #</p>
    </script>

If you set the PageSize option to a larger value, you will need to use a loop in the template.

Razor
    <script id="scrollview-template" type="text/x-kendo-template">
        # for (var i = 0; i < data.length; i++) { #
            <p style="border: 2px solid blue; color: red;">#= data[i].SomeField #</p>
        # } #
    </script>

Functionality and Features

  • Templates—To take control over the rendering of the ScrollView items, utilize the available templates.
  • Paging—Set an overlay background color for the ScrollView pager.
  • Events—Subscribe to the available client-side events to implement any custom logic.
  • Keyboard Navigation—The ScrollView delivers keyboard shortcuts for faster navigation.

Next Steps

See Also