In no way I am an ASP.net developer, however I was put to sort out an issue with a carousel appearing on a page, even taken that there are no slides to display. I've opened the code I've found from the previous developer and found this part (shortened):

@if (new SchoolWebber.Models.SiteViewModel().DisplayCarouselOnAllPages || ViewBag.IsHomePage != null) {

<div id="myCarousel" class="carousel slide" data-ride="carousel">

  <ol class="carousel-indicators">

    @{ var imagecounter = 0;} @foreach (var item in new SchoolWebber.Models.SiteViewModel().GetCarousel()) { if (imagecounter == 0) {
    <li data-target="#myCarousel" data-slide-to="@imagecounter" class="active"></li>
    } else {
    <li data-target="#myCarousel" data-slide-to="@imagecounter"></li>
    } imagecounter++; }
  </ol>

  ....

}

So, if I got it right, it checks if the carousel is set to be displayed on all pages, otherwise it shows it on the homepage. However, the problem is that it shows the carousel on the homepage, even taken that there are no items to display.

How do I apply here a condition that would count the number of items inside SchoolWebber.Models.SiteViewModel().GetCarousel() and show the carousel only if that number is greater than 0?

Related posts

Recent Viewed