Search results

Getting started with ASP.NET MVC Sidebar control

This section briefly explains how to include simple Sidebar control in your ASP.NET MVC application. You can refer to ASP.NET MVC Getting Started documentation page for system requirements, and configure common specifications.

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, you also have to include a license key in your projects. Please refer to this link to know about registering Syncfusion license key in your ASP.NET MVC application to use our components.

Adding component to the Application

  • Now open your view page to render Sidebar components.
 <!-- sidebar element declaration -->
@{Html.EJS().Sidebar("default-sidebar").CloseOnDocumentClick(false).ContentTemplate(@<div>
        <div class="title-header">
            <div style="display:inline-block"> Sidebar </div>
        </div>
</div>).Render();
}
<!-- end of sidebar element -->
<!--  Main Content declaration -->
<div>
    <div class="title default">Main content</div>
    <div class="sub-title">
        Place your primary content here.
    </div>
</div>

Run the application

After successful compilation of your application, simply press F5 to run the application.

The following example shows a basic Sidebar component.

razor
getting-started.cs
<!-- sidebar element declaration -->
@{Html.EJS().Sidebar("default-sidebar").CloseOnDocumentClick(false).ContentTemplate(
@<div>
    <div class="title-header">
        <div style="display:inline-block"> Sidebar </div>
    </div>
</div>).Render();
}
<!-- end of sidebar element -->
<!--  Main Content declaration -->
<div>
    <div class="title default">Main content</div>
    <div class="sub-title">
        Place your primary content here.
    </div>
</div>

<style>
    /* sample level styles */
    .center-align {
        text-align: center;
        padding: 20px;
    }

    .title {
        text-align: center;
        font-size: 20px;
        padding: 15px;
    }

    .sub-title {
        text-align: center;
        font-size: 16px;
        padding: 10px;
    }

    body {
        padding-top: 0px;
        padding-bottom: 0px;
    }

    .title-header {
        text-align: center;
        font-size: 18px;
        padding: 15px;
    }

    .title.default {
        padding: 25px 15px 15px;
    }
    /* sidebar element styles */
    #default-sidebar {
        background-color: rgb(25, 118, 210);
        color: #ffffff;
    }
</style>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace WebApplication.Controllers
{
    public partial class SidebarController : Controller
    {
        public IActionResult sample()
        {
            return View();
        }
    }
}

Output be like the below.

Sidebar Sample

Enable backdrop

Enabling the showBackdrop in the Sidebar component will prevent the main content from user interactions. Here, the DOM elements will not get changed. It only closes the main content by covering with a black backdrop overlay and focuses the Sidebar in the screen. Sidebar can be rendered with specific width by setting width property.

The following example shows a Sidebar component with enabled backdrop.

razor
backdrop.cs
<!-- sidebar element declaration -->
@{Html.EJS().Sidebar("default-sidebar").ShowBackdrop(true).Type(Syncfusion.EJ2.Navigations.SidebarType.Push).Width("280px").ContentTemplate(@<div>
    <div class="title"> Sidebar content</div>
    <div class="sub-title">
        Click the button to close the Sidebar.
    </div>
    <div class="center-align">
        <!-- button element declaration -->
        @Html.EJS().Button("close").Content("CloseSidebar").Render()
    </div>
</div>).Render();
}
<!-- end of sidebar element -->
<!-- main content declaration -->
<div>
    <div class="title">Main content</div>
    <div class="sub-title"> Click the button to open/close the Sidebar.</div>
    <div style="padding:20px" class="center-align">
        <!-- button element declaration -->
        @Html.EJS().Button("toggle").Content("Toggle Sidebar").CssClass("e-info").Render()
    </div>
</div>

<script type="text/javascript">
    document.addEventListener('DOMContentLoaded', function () {
        //create instances for sidebar element
        var defaultSidebar = document.getElementById("default-sidebar").ej2_instances[0];
        // Toggle button to close and open the sidebar
        document.getElementById('toggle').onclick = function () {
            defaultSidebar.toggle();
        }
        // Close the sidebar
        document.getElementById('close').onclick = function () {
            defaultSidebar.hide();
        }
    });
</script>

<style>
    /* sample level styles */
    .center-align {
        text-align: center;
        padding: 20px;
    }

    .title {
        text-align: center;
        font-size: 20px;
        padding: 15px;
    }

    .sub-title {
        text-align: center;
        font-size: 16px;
        padding: 10px;
    }
    /* Button styles */
    #close, #close:hover, #close:active, #close:focus { /* csslint allow: adjoining-classes*/
        background: #fafafa;
        color: black
    }
    /* sidebar element styles */
    #default-sidebar {
        background-color: rgb(25, 118, 210);
        color: #ffffff;
    }

</style>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace WebApplication.Controllers
{
    public partial class SidebarController : Controller
    {
        public IActionResult backdrop()
        {
            return View();
        }
    }
}

Output be like the below.

Sidebar Sample

Position

Positioning the Sidebar to the right or left of the main content can be achieved by using the position property. If the position is not set, the Sidebar will expand from the left to the body element.enablePersistence will persist the component’s state between page reloads. change event will be triggered when the state(expand/collapse) of the component is changed.

In the following sample, the sidebar is rendered with position property.

razor
position.cs
<!-- sidebar element declaration -->
@{Html.EJS().Sidebar("default-sidebar").Type(Syncfusion.EJ2.Navigations.SidebarType.Push).Width("280px").EnablePersistence(true).Target(".maincontent").ContentTemplate(@<div>
    <div class="title"> Sidebar content</div>
    <div class="sub-title">
        Click the button to close the Sidebar.
    </div>
    <div class="center-align">
        <!-- Button element declaration -->
        @Html.EJS().Button("close").Content("CloseSidebar").Render()
    </div>
</div>).Render();
}
<!-- end of sidebar element -->
<!--  Main Content declaration -->
<div id="head">
    <!-- Button element declaration -->
    @Html.EJS().Button("toggle").Content("Open").IsToggle(true).CssClass("e-info").IconCss("e-icons burg-icon").Render()
</div>
<div class="maincontent" style="height:335px;border:1px solid gray">
    <div>
        <div class="title">Main content</div>
        <div class="sub-title">
            <div class="column">
                <!-- RadioButton element declaration -->
                @Html.EJS().RadioButton("left").Label("Left").Name("state").Checked(true).Change("positionChange").Render()
            </div>
            <div class="column">
                <!-- RadioButton element declaration -->
                @Html.EJS().RadioButton("right").Label("Right").Name("state").Change("positionChange").Render()
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    document.addEventListener('DOMContentLoaded', function () {
        //create instances for sidebar element
        var defaultSidebar = document.getElementById("default-sidebar").ej2_instances[0];
          // Toggle button to close and open the sidebar
        document.getElementById('toggle').onclick = function () {
            var togglebtn = document.getElementById("toggle").ej2_instances[0];
            if (document.getElementById('toggle').classList.contains('e-active')) {
                togglebtn.content = 'Close';
                defaultSidebar.show();
            } else {
                togglebtn.content = 'Open';
                defaultSidebar.hide();
            }
        }
        // Close the sidebar
        document.getElementById('close').onclick = function () {
            defaultSidebar.hide();
            document.getElementById('toggle').classList.remove('e-active');
            var togglebtn = document.getElementById("toggle").ej2_instances[0];
            togglebtn.content = 'Open'
        }

    });
     // Change the position of sidebar
    function positionChange(args) {
        var defaultSidebar = document.getElementById("default-sidebar").ej2_instances[0];
        defaultSidebar.position = (args.event.target.id == "left") ? "Left" : "Right";
    }

</script>

<style>
    /* sample level styles */
    .center-align {
        text-align: center;
        padding: 20px;
    }

    .title {
        text-align: center;
        font-size: 20px;
        padding: 15px;
    }

    #head {
        border: 1px solid #424242;
        border-bottom-color: transparent;
        background: #00897B;
    }

    .sub-title {
        text-align: center;
        font-size: 16px;
        padding: 10px;
    }

    .column {
        display: inline-block;
        padding: 10px;
    }
    /* Icons styles */
    .burg-icon:before {
        content: '\e10d';
        font-size: 16px;
    }
    /* Sidebar element styles */
    #default-sidebar {
        background-color: #26A69A;
        color: #ffffff;
    }
    /* Button styles */
    .close-btn:hover {
        color: #fafafa;
    }

    .radiobutton {
        display: inline-block;
        padding: 10px;
    }

    #close, #close:hover, #close:active, #close:focus { /* csslint allow: adjoining-classes*/
        background: #fafafa;
        color: black
    }

    #toggle { /* csslint allow: adjoining-classes*/
        background: #00695C;
        box-shadow: none;
        border-radius: 0;
        height: 39px;
        width: 100px;
    }
    /* custom generated icons styles */
    @@font-face {
        font-family: 'e-icons';
        src: url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAAKAIAAAwAgT1MvMjciQ6oAAAEoAAAAVmNtYXBH1Ec8AAABsAAAAHJnbHlmKcXfOQAAAkAAAAg4aGVhZBLt+DYAAADQAAAANmhoZWEHogNsAAAArAAAACRobXR4LvgAAAAAAYAAAAAwbG9jYQukCgIAAAIkAAAAGm1heHABGQEOAAABCAAAACBuYW1lR4040wAACngAAAJtcG9zdEFgIbwAAAzoAAAArAABAAADUv9qAFoEAAAA//UD8wABAAAAAAAAAAAAAAAAAAAADAABAAAAAQAAlbrm7l8PPPUACwPoAAAAANfuWa8AAAAA1+5ZrwAAAAAD8wPzAAAACAAC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woKCAgHBQUDAgAAABIA3gABAAAAAAAAAAEAAAABAAAAAAABAA0AAQABAAAAAAACAAcADgABAAAAAAADAA0AFQABAAAAAAAEAA0AIgABAAAAAAAFAAsALwABAAAAAAAGAA0AOgABAAAAAAAKACwARwABAAAAAAALABIAcwADAAEECQAAAAIAhQADAAEECQABABoAhwADAAEECQACAA4AoQADAAEECQADABoArwADAAEECQAEABoAyQADAAEECQAFABYA4wADAAEECQAGABoA+QADAAEECQAKAFgBEwADAAEECQALACQBayBlLWljb25zLW1ldHJvUmVndWxhcmUtaWNvbnMtbWV0cm9lLWljb25zLW1ldHJvVmVyc2lvbiAxLjBlLWljb25zLW1ldHJvRm9udCBnZW5lcmF0ZWQgdXNpbmcgU3luY2Z1c2lvbiBNZXRybyBTdHVkaW93d3cuc3luY2Z1c2lvbi5jb20AIABlAC0AaQBjAG8AbgBzAC0AbQBlAHQAcgBvAFIAZQBnAHUAbABhAHIAZQAtAGkAYwBvAG4AcwAtAG0AZQB0AHIAbwBlAC0AaQBjAG8AbgBzAC0AbQBlAHQAcgBvAFYAZQByAHMAaQBvAG4AIAAxAC4AMABlAC0AaQBjAG8AbgBzAC0AbQBlAHQAcgBvAEYAbwBuAHQAIABnAGUAbgBlAHIAYQB0AGUAZAAgAHUAcwBpAG4AZwAgAFMAeQBuAGMAZgB1AHMAaQBvAG4AIABNAGUAdAByAG8AIABTAHQAdQBkAGkAbwB3AHcAdwAuAHMAeQBuAGMAZgB1AHMAaQBvAG4ALgBjAG8AbQAAAAACAAAAAAAAAAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwBAgEDAQQBBQEGAQcBCAEJAQoBCwEMAQ0AB2hvbWUtMDELQ2xvc2UtaWNvbnMHbWVudS0wMQR1c2VyB0JUX2luZm8PU2V0dGluZ19BbmRyb2lkDWNoZXZyb24tcmlnaHQMY2hldnJvbi1sZWZ0CE1UX0NsZWFyDE1UX0p1bmttYWlscwRzdG9wAAA=) format('truetype');
        font-weight: normal;
        font-style: normal;
    }
</style>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace WebApplication.Controllers
{
    public partial class SidebarController : Controller
    {
        public IActionResult position()
        {
            return View();
        }
    }
}

Output be like the below.

Sidebar Sample

Animate

Animation transitions can be set while expanding or collapsing the Sidebar using the animate property. By default , animate property is set to true. enableRTL will display the sidebar in the right-to-left direction.

razor
animate.cs
<!-- sidebar element declaration -->
@{Html.EJS().Sidebar("default-sidebar").Animate(false).EnableRtl(true).Type(Syncfusion.EJ2.Navigations.SidebarType.Push).Width("280px").ContentTemplate(@<div>
    <div class="title"> Sidebar content</div>
    <div class="sub-title">
        Click the button to close the Sidebar
    </div>
    <div class="center-align">
        <!-- button element declaration -->
        @Html.EJS().Button("close").Content("CloseSidebar").Render()
    </div>
</div>).Render();
}
<!-- end of sidebar element -->
<!-- main content declaration -->
<div>
    <div class="title">Main content</div>
    <div class="sub-title"> Click the button to open/close the Sidebar.</div>
    <div style="padding:20px" class="center-align">
        <!-- button element declaration -->
        @Html.EJS().Button("toggle").Content("Toggle Sidebar").CssClass("e-info").Render()
    </div>
</div>

<script type="text/javascript">
    document.addEventListener('DOMContentLoaded', function () {
        //create instances for sidebar element
        var defaultSidebar = document.getElementById("default-sidebar").ej2_instances[0];
        // Toggle button to close and open the sidebar
        document.getElementById('toggle').onclick = function () {
            defaultSidebar.toggle();
        }
        // Close the sidebar
        document.getElementById('close').onclick = function () {
            defaultSidebar.hide();
        }
    });
</script>

<style>
    /* sample level styles */
    .center-align {
        text-align: center;
        padding: 20px;
    }

    .title {
        text-align: center;
        font-size: 20px;
        padding: 15px;
    }

    .sub-title {
        text-align: center;
        font-size: 16px;
        padding: 10px;
    }
    /* Button styles */
    #close, #close:hover, #close:active, #close:focus { /* csslint allow: adjoining-classes*/
        background: #fafafa;
        color: black
    }
    /* sidebar element styles */
    #default-sidebar {
        background-color: rgb(25, 118, 210);
        color: #ffffff;
    }

</style>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace WebApplication.Controllers
{
    public partial class SidebarController : Controller
    {
        public IActionResult animate()
        {
            return View();
        }
    }
}

Output be like the below.

Sidebar Sample

Close on document click

Sidebar can be closed on document click by setting closeOnDocumentClick to true. If this property is not set, the Sidebar will not close on document click since its default value is false. Sidebar can be kept opened during rendering using isOpen property.

razor
<!-- sidebar element declaration -->
@{Html.EJS().Sidebar("default-sidebar").CloseOnDocumentClick(true).IsOpen(true).Type(Syncfusion.EJ2.Navigations.SidebarType.Push).Width("280px").ContentTemplate(@<div>
    <div class="title"> Sidebar content</div>
</div>).Render();
}
<!-- end of sidebar element -->
<!-- main content declaration -->
<div>
    <div class="title">Main content</div>
    <div class="sub-title"> Click the button to open/close the Sidebar.</div>
    <div style="padding:20px" class="center-align">
        <!-- button element declaration -->
        @Html.EJS().Button("toggle").Content("Open Sidebar").CssClass("e-info").Render()
    </div>
</div>

<script type="text/javascript">
    document.addEventListener('DOMContentLoaded', function () {
        //create instances for sidebar element
        var defaultSidebar = document.getElementById("default-sidebar").ej2_instances[0];
        // Toggle button to close and open the sidebar
        document.getElementById('toggle').onclick = function () {
            defaultSidebar.show();
        }
    });
</script>

<style>
    /* sample level styles */
    .center-align {
        text-align: center;
        padding: 20px;
    }

    .title {
        text-align: center;
        font-size: 20px;
        padding: 15px;
    }

    .sub-title {
        text-align: center;
        font-size: 16px;
        padding: 10px;
    }
    /* Button styles */
    #close, #close:hover, #close:active, #close:focus { /* csslint allow: adjoining-classes*/
        background: #fafafa;
        color: black
    }
    /* sidebar element styles */
    #default-sidebar {
        background-color: rgb(25, 118, 210);
        color: #ffffff;
    }

</style>

Output be like the below.

Sidebar Sample

Enable gestures

Expand or collapse the Sidebar while swiping in touch devices using enableGestures property. By default, enableGestures is set to true.

razor
gestures.cs
<!-- sidebar element declaration -->
@{Html.EJS().Sidebar("default-sidebar").EnableGestures(true).Type(Syncfusion.EJ2.Navigations.SidebarType.Push).Width("280px").ContentTemplate(@<div>
    <div class="title"> Sidebar content</div>
    <div class="sub-title">
        Click the button to close the Sidebar
    </div>
    <div class="center-align">
        <!-- button element declaration -->
        @Html.EJS().Button("close").Content("CloseSidebar").Render()
    </div>
</div>).Render();
}
<!-- end of sidebar element -->
<!-- main content declaration -->
<div>
    <div class="title">Main content</div>
    <div class="sub-title"> Click the button to open/close the Sidebar.</div>
    <div style="padding:20px" class="center-align">
        <!-- button element declaration -->
        @Html.EJS().Button("toggle").Content("Toggle Sidebar").CssClass("e-info").Render()
    </div>
</div>

<script type="text/javascript">
    document.addEventListener('DOMContentLoaded', function () {
        //create instances for sidebar element
        var defaultSidebar = document.getElementById("default-sidebar").ej2_instances[0];
        // Toggle button to close and open the sidebar
        document.getElementById('toggle').onclick = function () {
            defaultSidebar.toggle();
        }
        // Close the sidebar
        document.getElementById('close').onclick = function () {
            defaultSidebar.hide();
        }
    });
</script>

<style>
    /* sample level styles */
    .center-align {
        text-align: center;
        padding: 20px;
    }

    .title {
        text-align: center;
        font-size: 20px;
        padding: 15px;
    }

    .sub-title {
        text-align: center;
        font-size: 16px;
        padding: 10px;
    }
    /* Button styles */
    #close, #close:hover, #close:active, #close:focus { /* csslint allow: adjoining-classes*/
        background: #fafafa;
        color: black
    }
    /* sidebar element styles */
    #default-sidebar {
        background-color: rgb(25, 118, 210);
        color: #ffffff;
    }

</style>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace WebApplication.Controllers
{
    public partial class SidebarController : Controller
    {
        public IActionResult gestures()
        {
            return View();
        }
    }
}

Output be like the below.

Sidebar Sample

See Also