September 5, 2013

JQuery Carousel Control in ASP.NET MVC4 Razor

In this post, I tell you how to build Carousel control in MVC4 using Razor engine. You find plenty of websites containing code implementation related to web form architecture but on MVC framework this ratio is quite low. It is expected you have basic knowledge on what is JQuery. 

Follow these parameters to run Jquery Carousel control in MVC4.

1. You need to download the jcarousellite_1.0.1.js file. Click here to download that file. Place that file in Script folder present in root directory of your MVC4 project.

2. Add above JS script reference in RegisterBundles method of BundleConfig.cs under App_Start folder present in root directory as shown below:

bundles.Add(new ScriptBundle("~/bundles/jquerycarousel").Include(

3. Add the folder in root directory of application named as "SlideImages" and add some images there which are use in Carousel control.

4. In Home Controller Action method, create a ViewBag of images present in SlideImages folder as:

public ActionResult Index()
   var imageList = new 
   ViewBag.ImageList = imageList;

   return View();

5. Index View of Home controller is becomes now as:

    ViewBag.Title = "Index";    

@* Add Jquery bundle here before script tag *@
<script type="text/javascript">

  $(function () {

    // Add Carousel plugin to rotate images
auto: 800,
speed: 800


@section featured {
    <section class="featured">
        <div class="content-wrapper">
            <hgroup class="title">
                  JQuery Carousel Control in MVC4 using Razor 

@using (Html.BeginForm("Index", "Home", FormMethod.Post))

    <div class="imageSlider">
         @foreach (var item in ViewBag.ImageList)
               <img src="@Url.Content("~/SlideImages/" + item)" 
                    alt="" width="250" height="150" />

@* Add Jquery Carousel bundle here *@

@section Scripts {

This will start Carousel control to display images automatically one by one. As you see the code which is very simple and easy as compare to web forms. I hope that you get all the points to understand how it is working. Let me know if any query remains. Stay tune. :)


  1. The Carousel .NET component is able to create interactive navigation user interface to .NET application.

  2. Sounds awesome, it would be better if there are things about the Carousel Control Tutorial.

  3. Hi, its a great example! It was very useful to me in my web page, but I have a question, and is about using media queries with responsive design... There is a solution to work with different dimensions of images, for example to show the carousel in smartphones or tablets?