New to Telerik UI for ASP.NET MVC? Download free 30-day trial

ListBox in Razor Pages

Razor Pages is an alternative to the MVC pattern that makes page-focused coding easier and more productive. This approach consists of a cshtml file and a cshtml.cs file (by design, the two files have the same name).

You can seamlessly integrate the Telerik UI ListBox for ASP.NET MVC in Razor Pages applications.

This article describes how to configure the ListBox component in a Razor Pages scenario.

For the complete project, refer to the ListBox in Razor Pages example.

Getting Started

To bind the Telerik UI ListBox to a data set within a RazorPage:

  1. Setup the Read URL in the DataSource. The URL should refer the name of the method in the PageModel.

        .DataSource(ds=>ds
            .Read(r=>r.Url("/ListBox/ListBoxBinding?handler=ReadOptional"))
        )
    
    <datasource>
        <transport>
            <read url="/ListBox/ListBoxBinding?handler=ReadOptional"/>
        </transport>
    </datasource>
    
  2. Within the .cs file, introduce an ActionMethod to return the data set:

        public JsonResult OnGetReadOptional()
        {
            return new JsonResult(ListBoxItems);
        }
    

See Also

In this article