Search results

Getting Started

This section briefly explains about how to include a Accordion in your Blazor client-side application. You can refer Getting Started with Syncfusion Blazor for Client-Side in Visual Studio 2019 Preview page for the introduction and configuring the common specifications.

Importing Syncfusion Blazor component in the application

  1. Install Syncfusion.EJ2.Blazor NuGet package to the application by using the NuGet Package Manager. Please ensure to check the Include prerelease option.

  2. You can add the client-side resources through CDN or local npm package in the <head> element of the ~/wwwroot/index.html page.

   <head>
       <link href="https://cdn.syncfusion.com/ej2/17.3.29/material.css" rel="stylesheet" />
       <script src="https://cdn.syncfusion.com/ej2/17.3.29/dist/ej2.min.js"></script>
   </head>

Adding component package to the application

Open ~/_Imports.razor file and import the Syncfusion.EJ2.Blazor.Navigations packages.

    @using Syncfusion.EJ2.Blazor
    @using Syncfusion.EJ2.Blazor.Navigations

Adding Accordion component to the application

Now, add the Syncfusion Blazor Accordion component in any web page (razor) in the Pages folder. For example, the Accordion component is added in the ~/Pages/Index.razor page.

@using Syncfusion.EJ2.Blazor.Navigations

<EjsAccordion>
    <AccordionItems>
        <AccordionItem Header="Margeret Peacock" Content="Margeret Peacock was born on Saturday , 01 December 1990. Now lives at Coventry House Miner Rd., London,UK. Margeret Peacock holds a position of Sales Coordinator in our WA department, (Seattle USA). Joined our company on Saturday , 01 May 2010"></AccordionItem>
        <AccordionItem Header="Laura Callahan" Content="Laura Callahan was born on Tuesday , 06 November 1990. Now lives at Edgeham Hollow Winchester Way, London,UK. Laura Callahan holds a position of Sales Coordinator in our WA department, (Seattle USA). Joined our company on Saturday , 01 May 2010"></AccordionItem>
        <AccordionItem Header="Albert Dodsworth" Content="Albert Dodsworth was born on Thursday , 19 October 1989. Now lives at 4726 - 11th Ave. N.E., Seattle,USA.Albert Dodsworth holds a position of Sales Representative in our WA department, (Seattle USA). Joined our company on Friday , 01 May 2009"></AccordionItem>
    </AccordionItems>
</EjsAccordion>

Run the application

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

output

Initialize Accordion using Template

The following code explains how to initialize accordion using Template.

@using Syncfusion.EJ2.Blazor.Navigations

<EjsAccordion>
    <AccordionItems>
        <AccordionItem>
            <HeaderTemplate>
                <div>Margeret Peacock</div>
            </HeaderTemplate>
            <ContentTemplate>
                <div class='container'><img src='images/margeret.png' /><div class='content'><b>Margeret Peacock</b> was born on Saturday , 01 December 1990. Now lives at Coventry House Miner Rd., London,UK. Margeret Peacock holds a position of <b>Sales Coordinator</b> in our WA department, (Seattle USA). Joined our company on Saturday , 01 May 2010.</div></div>">
            </ContentTemplate>
        </AccordionItem>
        <AccordionItem>
            <HeaderTemplate>
                <div>Laura Callahan</div>
            </HeaderTemplate>
            <ContentTemplate>
                <div class='container'><img src='images/laura.png'/><div class='content'><b>Laura Callahan</b> was born on Tuesday , 06 November 1990. Now lives at Edgeham Hollow Winchester Way, London,UK. Laura Callahan holds a position of <b>Sales Coordinator</b> in our WA department, (Seattle USA). Joined our company on Saturday , 01 May 2010.</div></div>
            </ContentTemplate>
        </AccordionItem>
        <AccordionItem>
            <HeaderTemplate>
                <div>Albert Dodsworth</div>
            </HeaderTemplate>
            <ContentTemplate>
                <div class='container'><img src='images/albert.png' /><div class='content'> <b>Albert Dodsworth</b> was born on Thursday , 19 October 1989. Now lives at 4726 - 11th Ave. N.E., Seattle,USA.Albert Dodsworth holds a position of <b>Sales Representative</b> in our WA department, (Seattle USA). Joined our company on Friday , 01 May 2009.</div></div>
            </ContentTemplate>
        </AccordionItem>
    </AccordionItems>
</EjsAccordion>

<style>

    img {
        height: 40px;
        width: 50px;
        margin-top: 13px;
    }

    .container {
        display: inline-flex;
        width: auto;
        padding: 0;
    }

    .content {
        margin-left: 10px;
    }

</style>

Output be like the below.

Accordion with template

See Also

  1. Getting Started with Syncfusion Blazor for Client-Side in .NET Core CLI
  2. Getting Started with Syncfusion Blazor for Server-side in Visual Studio 2019 Preview
  3. Getting Started with Syncfusion Blazor for Server-Side in .NET Core CLI