To make this simple
If you look at the HTML from http://getbootstrap.com/javascript/#carousel
Copy the first and add Razor , this should create a carousel for you.
@model List<YOUR_MODEL_NAME> @{var j = 0;} <div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> <ol class="carousel-indicators"> @for (var i = 0; i < Model.Count(); i++) { <li data-target="#carousel-example-generic" data-slide-to="@i"></li> } </ol> <div class="carousel-inner" role="listbox"> @foreach (var item in Model) { <div class="item @(j == 0 ? "active" : "")"> <img src="@(string.Format("/Images/profile/{0}", item.ImagePath))" /> </div> @(j = 1) } </div> <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next"> <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div>
EDIT
Below is an example of thumbnails, clicking on the thumbnails will open a modal dialog box with a carousel.
I created a JSFiddle of your script: http://jsfiddle.net/u7hxy3zc/1/
As an example, you should use the following code and use in your presentation, renaming all models and parameters.
Note. The following code has not been compiled. May have syntax errors.
// DISPLAY THUMBNAILS <div class="col-md-2"> @for(int i =0; i < Model.Count(); i++) { <img src="@Model[i].ImageUrl" data-id="@i" data-action="image" /> } </div> .......... REMOVE HTML TO MAKE EXAMPLE CLEAR ... MODAL DIALOG START................. <div class="modal-body"> ...........CAROUSEL START............ <div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> <ol class="carousel-indicators"> @for(var i = 0 ; i< Model.Count(); i++) { <li data-target="#carousel-example-generic" data-slide-to="@i"></li> } </ol> <div class="carousel-inner" role="listbox"> @for(var i = 0; i < Model.Count(); i++) { <div class="item" data-image-id="@i"> // DISPLAY i for Testing @i <img src="@Model[i].ImageUrl" /> } </div> ........... REMOVED REST OF CAROUSEL......(NEXT / PREV BUTTONS)......... .............CAROUSEL END...................
Then add this jQuery to the end to trigger the click event:
$('body').on('click', '*[data-action="image"]', function (e) { e.stopPropagation(); var img = $(this); var currentId = img.data('id'); $('#myModal').modal(); var currentSlide = "*[data-slide-to='" + currentId + "']"; var currentImagSlide = "*[data-image-id='" + currentId + "']"; console.log(currentSlide); $("*[data-slide-to]").removeClass("active"); $(".item").removeClass("active"); var item = $('.carousel-indicators').find(currentSlide); var imgItem = $('.carousel-inner').find(currentImagSlide); console.log(item); item.addClass("active"); imgItem.addClass("active"); });
Dawood awan
source share