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

Change Theme On The Client


Product Progress® Telerik® UI for UI for ASP.NET Core


How can I allow the user to change the theme in my Telerik UI for ASP.NET Core application?


The Step by Step guide below demonstrates how to allow the user to change the theme of the application. The approach demonstrated uses cookies to store the theme selected by the user.

Adding a DropDownList for theme selection

Add a UI for ASP.NET Core DropDownList to the _Layout.cshtml file for theme selection.

        .OptionLabel("Select Theme")
        .DataSource(source =>
            source.Read(read =>
                    read.Action("GetThemes", "Home");
            }).Events(ev => ev.Change("themeSelection"))
        .HtmlAttributes(new { style = "float: right" })

Sending information on the selected theme to the server

Upon selection of a theme, pass the selected theme name to an action method responsible for setting the theme.

    function themeSelection(e) {
        var selectedTheme = e.sender.dataItem();
            url: "/Home/SetTheme",
            data: { selection: selectedTheme.ThemeId },
            success: function (data) {
                window.location = data.url;

Append the name of the selected theme to a cookie.

    public IActionResult SetTheme(string selection)
        CookieOptions cookie = new CookieOptions();
        cookie.Expires = DateTime.Now.AddMinutes(10);

        Response.Cookies.Append("theme", selection, cookie);
        var returnUrl = Request.Headers["Referer"].ToString();
        return Json(new { result = "Redirect", url = returnUrl });

Loading the selected theme

Set the theme in the _Layout.cshtml file, by following the requirements discussed in the Including Client-Side Resources article. In the current example, the selected theme name is retrieved from the cookie and the CDN url for theme is generated. An alternative approach, if stylesheets are stored within the application, would be to generate the url to the stylesheet for the selected theme.

        var mainHref = "";
        var selectedTheme = "classic/classic-main";

        if (Request.Cookies["theme"] != null)
            selectedTheme = Request.Cookies["theme"].Value;

        if (selectedTheme == "custom")
            <link rel="stylesheet" href="~/css/styles/kendo.custom.css" />

            var themeHref = mainHref + selectedTheme + ".css";
            <link href=@themeHref rel="stylesheet" type="text/css" />

See Also

In this article