Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
How to use owl carousel in blazor?

I'm using the Owl Carrousel library in a webassembly project, the carousel works fine for me when the images are static:

<img class="rounded-1 img-fluid" src="Img/CP5.png" alt="" / >

The problem arises when I want the images to be dynamic and come from the database, the carousel is not shown and when it is shown it does not work as it should, all the styles and functionality are lost, could you help me with this please.

this is my class where do I store the images in the database:

 public class Carrusel
    {
        public int CarruselId { get; set; }      
        public string Imagen { get; set; }
    }

on my blazor page I have this:

 @if (ListadeCarrusel != null)
{
<div class="owl-carousel owl-theme">
    @foreach (var item in ListadeCarrusel)
    {
        <div style="height:300px; width:100%;">
            <img class="rounded-1 img-fluid" src="@item.Imagen" alt="" />
        </div>
    }
</div>
}
    @code{
    
     protected override async Task OnInitializedAsync()
     {
        await CargarCarrusel();
     }
    
     public List<Carrusel> ListadeCarrusel { get; set; }
    
        private async Task CargarCarrusel()
        {
            var responseHttp = await repositorio.Get<List<Carrusel>>($"api/Carrusel");
            if (!responseHttp.Error)
            {
                ListadeCarrusel = responseHttp.Response;
            }
        }
    
        protected async override Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
            {
                await JS.InvokeVoidAsync("OwlCarousel");
                firstRender = false;
                StateHasChanged();
            }
        }
    }

in js file i have this:

function OwlCarousel() {
    $(".owl-carousel").owlCarousel({
        loop: true,
        items: 1,
        nav: false,
        autoplay: true,
        dots: true,
        autoHeight: true
    });
};

I think that the div with the owl carousel class, being inside the if, does not take the css and functionalities that make it work well, but I am not sure, I have no idea what is happening

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!