Click here to Skip to main content
14,423,213 members

Make bootstrap caraousel work with razor ASP.NET core and modelbinding

Stefaneus asked:

Open original thread
Hello can anyone help me with this? i am trying to make a carousel with bootstrap, and i am using images from my db, but as you can see in the picture, both images are showing with no consideration to the carousel, any ideas how i can fix this? the code looks like this.

<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
@for (int i = 0; i <; i++)
if (i == 0)
<li data-target="#carouselExampleIndicators" data-slide-to="@i" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="@i"></li>
<div class="carousel-inner">
<div class="carousel-item active">
@if ( != null)
@foreach (var i in
<img class="img-fluid" src="~/Images/Cars/@i.Filename" alt="First slide">
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
<span class="sr-only">Previous</span>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon"></span>
<span class="sr-only">Next</span>

What I have tried:

I have tested to place the for loop and the foreach loop in different places but to no avail, anyone got any solution?
Tags: C#, ASP.NET-Core, Razor


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100