There is an issue with the Kendo UI button group - it does not display in a partial view contained within a parent page that is contained within a layout page.

1 Answer 7 Views
Button
Acadia
Top achievements
Rank 1
Iron
Acadia asked on 25 Jun 2024, 06:48 PM

If I place a simple Kendo Button in the partial page it shows fine, but the button group does not show at all.  The developer tools and debugging shows everything to be correct and the partial view is being returned via return PartialView(partialViewName); from the controller.

This is driving me crazy.  Is this a known issue?  There are no errors in the console/developer tools.  It is specific to the Kendo Button GROUP.

Please help...thanks!

The view that contains the partial view:

@using Kendo.Mvc.UI

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div style="max-width:45rem;">
    <div>Administrative Areas</div>
    <div id="buttonGroup">
        @(Html.Kendo().ButtonGroup()
            .Name("adminButtonGroup")
            .Items(t =>
            {
                t.Add().Text("Personal").HtmlAttributes(new { onclick = "loadPartial('_Admin')" });
                t.Add().Text("Predefined").HtmlAttributes(new { onclick = "loadPartial('_Admin')" });
                t.Add().Text("Regions").HtmlAttributes(new { onclick = "loadPartial('_Admin')" });
                t.Add().Text("Flags").HtmlAttributes(new { onclick = "loadPartial('_Admin')" });
            })
            )
    </div>
</div>

<div id="adminPartial" class="mt-2">

</div>

<script>

    $(function () {
        // Set the first button as active by default
        $("#adminButtonGroup").data("kendoButtonGroup").select(0);

    });

    function loadPartial(partialViewName) { //clickedElement
        var targetDiv = document.getElementById("adminPartial");

        console.log(targetDiv.innerHTML);

        fetch('/Home/LoadPartialView?partialViewName=' + partialViewName)
            .then(response => response.text())
            .then(html => {
                targetDiv.innerHTML = html;
                console.log("partial view html:" + html);
            })
            .catch(error => {
                console.log('Error:', error);
            });
    }
</script>

 

Contents of the _Admin partial View: (does not display):

@using Kendo.Mvc.UI

<div>
@(Html.Kendo().ButtonGroup()
            .Name("adminPartialButtonGroup")
            .Items(t =>
            {
                t.Add().Text("Test 1");
                t.Add().Text("Test 2");
                t.Add().Text("Test 3");
                t.Add().Text("Test 4");
            })
            )
</div>

<script>

Home Controller Action:

 public IActionResult LoadPartialView(string partialViewName)
 {
     if (string.IsNullOrEmpty(partialViewName))
     {
         return BadRequest();
     }

     return PartialView(partialViewName);
 }

 

1 Answer, 1 is accepted

Sort by
0
Tsvetomila
Telerik team
answered on 28 Jun 2024, 10:33 AM

Hi Justin,

Thanks for the source code, it proved helpful. Based on that, I suggest slightly changing the JavaScript in the view. 

#1 Add default partial view:

<script>
    $(function () {
        // Set the first button as active by default
        $("#adminButtonGroup").data("kendoButtonGroup").select(0);

        // Set the partial of the first button as the default
        $("#adminPartial").load('/Home/LoadPartialView?partialViewName=' + '_Admin');
    });  

#2 Change fetch to load function:

    function loadPartial(partialViewName) { //clickedElement
        var targetDiv = document.getElementById("adminPartial");

        //Loads the partial view from the controller
        $("#adminPartial").load('/Home/LoadPartialView?partialViewName=' + partialViewName);
        // the fetch function is removed
    }
</script>

These amendments should accomplish the task and allow you to keep most of your existing code.

Let me know if that suggestion works for you.

Regards,
Tsvetomila
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.
Tags
Button
Asked by
Acadia
Top achievements
Rank 1
Iron
Answers by
Tsvetomila
Telerik team
Share this question
or