Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

230
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda