# ASP.NET Core ListView Overview

The Telerik UI ListView TagHelper and HtmlHelper for ASP.NET Core are server-side wrappers for the Kendo UI ListView widget. To add the component to your ASP.NET Core app, you can use either.

The ListView enables you to display a custom layout of data-bound items. The ListView is ideally suited for displaying a list of items in a consistent manner. You can see commonplace examples of its use in the design structures of the Internet, search engine results, tweets from Twitter, Facebook updates, inbox items in Gmail, card lists in Trello, and so on.

The ListView enables you to control the display of data. It does not provide a default rendering of data-bound items. Instead, it relies on templates to define the way a list of items is displayed, including alternating items and items that are in the process of editing.

* [Demo page for the ListView](https://demos.telerik.com/aspnet-core/listview/index)

## Initializing the ListView

The following example demonstrates how to define the ListView.

* The `TagName` of the ListView for ASP.NET Core is used to create an element to contain all ListView items once the ListView is bound.
* The `ClientTemplateId` is mandatory for the ListView. It contains the `id` of the `script` element which accommodates the item template.

```Razor HtmlHelper
    @(Html.Kendo().ListView()
        .Name("productListView") // The name of the ListView is mandatory. It specifies the "id" attribute of the widget.
        .TagName("div") // The tag name of the ListView is mandatory. It specifies the element which wraps all ListView items.
        .ClientTemplateId("template") // This template will be used for rendering the ListView items.
        .DataSource(dataSource => {
                dataSource.Read(read => read.Action("Products_Read", "ListView"));
        }) // The DataSource configuration. It will be used on paging.
        .Pageable() // Enable paging.
    )
```

```Razor TagHelper
    <kendo-listview name="productListView"
        tag-name="div"
        template-id="template">
        <datasource type="DataSourceTagHelperType.Ajax" page-size="9">
            <transport >
                <read url="@Url.Action("Products_Read", "ListView")" />
            </transport>
        </datasource>
        <pageable enabled="true"/>
    </kendo-listview>
```

```JS Template
    <script type="text/x-kendo-tmpl" id="template">
        <div class="product">
            <h3>#=ProductName#</h3>
            <dl>
                <dt>Price:</dt>
                <dd>#=kendo.toString(UnitPrice, "c")#</dd>
            </dl>
        </div>
    </script>
```

```C# Controller
    public partial class ListViewController : BaseController
    {
        private IProductService productService;

        public ListViewController(IProductService service)
        {
            productService = service;
        }

        public ActionResult Products_Read([DataSourceRequest] DataSourceRequest request)
        {
            return Json(GetProducts().ToDataSourceResult(request));
        }

        private IEnumerable<ProductViewModel> GetProducts()
        {
            using (var northwind = GetContext())
            {
                return northwind.Products.Select(product => new ProductViewModel
                {
                    ProductID = product.ProductID,
                    ProductName = product.ProductName,
                    UnitPrice = product.UnitPrice.HasValue ? product.UnitPrice.Value : default(decimal),
                    UnitsInStock = product.UnitsInStock.HasValue ? product.UnitsInStock.Value : default(int),
                    UnitsOnOrder = product.UnitsOnOrder.HasValue ? product.UnitsOnOrder.Value : default(int),
                    Discontinued = product.Discontinued,
                    LastSupply = DateTime.Today
                }).ToList();
            }
        }
    }
```

## Basic Configuration

The following example demonstrates the basic configuration for the ListView.

```Razor HtmlHelper
    @(Html.Kendo().ListView<Kendo.Mvc.Examples.Models.ProductViewModel>(Model)
        .Name("listView")
        .TagName("div")
        .ClientTemplateId("template")
        .DataSource(dataSource => dataSource
            .Model(model => model.Id("ProductID"))
            .PageSize(4)
            .Read(read => read.Action("Editing_Read", "ListView"))
            .Update(update => update.Action("Editing_Update", "ListView"))
            .Destroy(destroy => destroy.Action("Editing_Destroy", "ListView"))
        )
        .Pageable()
        .Editable()
    )
```

```Razor TagHelper
    <kendo-listview name="listView"
        tag-name="div"
        template-id="template"
        edit-template-id="editTemplate">
        <datasource type="DataSourceTagHelperType.Ajax" page-size="4">
            <transport>
                <read url="@Url.Action("Orders_Read", "ListView")"  />
                <update url="@Url.Action("Orders_Update", "ListView")"  />
                <destroy url="@Url.Action("Orders_Destroy", "ListView" )" />
            </transport>
            <schema>
                <model id="ProductID">
                    <fields>
                        <field name="ProductName"></field>
                        <field name="UnitPrice"></field>
                        <field name="UnitsInStock"></field>
                        <field name="Discontinued"></field>
                    </fields>
                </model>
            </schema>
        </datasource>
        <pageable enabled="true"/>
    </kendo-listview>
```

```JS Templates
    <script type="text/x-kendo-tmpl" id="template">
        <div class="product-view k-widget">
            <dl>
                <dt>Product Name</dt>
                <dd>#:ProductName#</dd>
                <dt>Unit Price</dt>
                <dd>#:kendo.toString(UnitPrice, "c")#</dd>
                <dt>Units In Stock</dt>
                <dd>#:UnitsInStock#</dd>
                <dt>Discontinued</dt>
                <dd>#:Discontinued#</dd>
            </dl>
            <div class="edit-buttons">
                <a class="k-button k-edit-button" href="\\#"><span class="k-icon k-i-edit"></span></a>
                <a class="k-button k-delete-button" href="\\#"><span class="k-icon k-i-delete"></span></a>
            </div>
        </div>
    </script>

    <script type="text/x-kendo-tmpl" id="editTemplate">
        <div class="product-view k-widget">
            <dl>
                <dt>Product Name</dt>
                <dd>
                    <span class="k-textbox k-input">
                        <input type="text" class="k-input-inner" data-bind="value:ProductName" name="ProductName" required="required" validationMessage="required" />
                    </span>
                    <span data-for="ProductName" class="k-invalid-msg"></span>
                </dd>
                <dt>Unit Price</dt>
                <dd>
                    <input type="text" data-bind="value:UnitPrice" data-role="numerictextbox" data-type="number" name="UnitPrice" required="required" min="1" validationMessage="required" />
                    <span data-for="UnitPrice" class="k-invalid-msg"></span>
                </dd>
                <dt>Units In Stock</dt>
                <dd>
                    <input type="text" data-bind="value:UnitsInStock" data-role="numerictextbox" name="UnitsInStock" required="required" data-type="number" min="0" validationMessage="required" />
                    <span data-for="UnitsInStock" class="k-invalid-msg"></span>
                </dd>
                <dt>Discontinued</dt>
                <dd><input type="checkbox" name="Discontinued" data-bind="checked:Discontinued"></dd>
            </dl>
            <div class="edit-buttons">
                <a role="button" class="k-button k-update-button" href="\\#"><span class="k-button-icon k-icon k-i-check"></span></a>
                <a role="button" class="k-button k-cancel-button" href="\\#"><span class="k-button-icon k-icon k-i-cancel"></span></a>
            </div>
        </div>
    </script>
```

## Functionality and Features

| Feature                                                                                                                            | Description                                                                                                                                                                                                    |
| ---------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Ajax binding](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/listview/binding/ajax-binding)    | You can bind the ListView to an [Ajax DataSource](https://docs.telerik.com/aspnet-core/html-helpers/datasource/types#ajax-datasource) which formats the request and parses the server response out-of-the-box. |
| [Editing](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/listview/editing)                      | To customize the editing functionality of the ListView, configure the provided editing templates.                                                                                                              |
| [Paging](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/listview/paging)                        | The ListView component supports the paging functionality.                                                                                                                                                      |
| [Templates](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/listview/templates)                  | To customize the visualization of the ListView items, use the provided [Kendo templates](https://docs.telerik.com/kendo-ui/framework/templates/overview).                                                      |
| [Scroll modes](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/listview/scrolling)               | ListView enables you to use the default scroll mode or utilize endless scrolling.                                                                                                                              |
| [Selection](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/listview/selection)                  | Choose between single or multiple selection mode.                                                                                                                                                              |
| [Globalization](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/listview/globalization/overview) | The ListView component allows you to adapt your apps for international users by translating the component messages and applying a right-to-left layout.                                                        |
| [Accessibility](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/listview/accessibility/overview) | The ListView is accessible by screen readers and provides WAI-ARIA, Section 508, WCAG 2.2, and keyboard support.                                                                                               |

## Next Steps

* [Getting Started with ListView](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/listview/getting-started-listview)

* [Basic Usage of the ListView for ASP.NET Core (Demo)](https://demos.telerik.com/aspnet-core/listview/index)

* [ListView in Razor Pages](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/listview/binding/razor-page)

## See Also

* [Basic Usage of the ListView HtmlHelper for ASP.NET Core (Demo)](https://demos.telerik.com/aspnet-core/listview/index)
* [Server-Side API](https://www.telerik.com/aspnet-core-ui/documentation/api/listview)
