# 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.

* [Demo page for the ScrollView HtmlHelper](https://demos.telerik.com/aspnet-mvc/scrollview/index)

## Initializing the ScrollView

You can initialize the ScrollView either [from HTML](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/media/scrollview/overview#from-html) or [from a data source with a template](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/media/scrollview/overview#from-the-data-source).

### From HTML

1. Use its `Items()` method.
2. Add HTML elements for each page as part of the content of the ScrollView items.

```Razor HtmlHelper
    <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](https://docs.telerik.com/kendo-ui/framework/templates/overview).
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 HtmlHelper
    @(Html.Kendo().ScrollView()
         .Name("scrollView")
         .ContentHeight("100%")
         .TemplateId("employee-template")
         .DataSource(d =>
                d.Custom()
                  .Type("odata-v4")
                  .Transport(t => t.Read(r => r.Url("https://demos.telerik.com/service/v2/odata/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 HtmlHelper
    @(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>
```

```C# Controller
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult GetScrollViewData([DataSourceRequest]DataSourceRequest request)
        {
            IEnumerable<MyModel> data = Enumerable.Range(1, 5).Select(x => new MyModel { SomeField = "item " + x + " from page " + request.Page });
            
            return Json(data.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
    }
```

```C# Model
    public class MyModel
    {
        public string SomeField { get; set; }
    }
```

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

```JS
    <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](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/media/scrollview/templates)—To take control over the rendering of the ScrollView items, utilize the available templates.
* [Paging](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/media/scrollview/paginig)—Set an overlay background color for the ScrollView pager.
* [Events](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/media/scrollview/events)—Subscribe to the available client-side events to implement any custom logic.
* [Keyboard Navigation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/media/scrollview/keyboard-navigation)—The ScrollView delivers keyboard shortcuts for faster navigation.

## Next Steps

* [Getting Started with the ScrollView](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/media/scrollview/getting-started)
* [Basic Usage of the ScrollView HtmlHelper for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/scrollview)

## See Also

* [Using the API of the ScrollView for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/scrollview/api)
* [Server-Side API of the ScrollView](https://www.telerik.com/aspnet-mvc/documentation/api/scrollview)
* [Client-Side API of the ScrollView](https://docs.telerik.com/kendo-ui/api/ui/scrollview)
* [Knowledge Base Section](https://www.telerik.com/aspnet-mvc/documentation/knowledge-base)
