In this tutorial I will show you if it is home page then display content in asp.net MVC.
STEP 1: Create a partial view "_slider.cshtml"
<!--Carousel Wrapper--> <div id="carousel-example-2" class="carousel slide carousel-fade mb-5" data-ride="carousel"> <!--Indicators--> <ol class="carousel-indicators"> <li data-target="#carousel-example-2" data-slide-to="0" class="active"></li> <li data-target="#carousel-example-2" data-slide-to="1"></li> <li data-target="#carousel-example-2" data-slide-to="2"></li> </ol> <!--/.Indicators--> <!--Slides--> <div class="carousel-inner" role="listbox"> <div class="carousel-item active"> <div class="view hm-white-slight"> <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(147).jpg" alt="First slide"> <div class="mask"></div> </div> <div class="carousel-caption"> <h3 class="h3-responsive">First title</h3> <p>First text</p> </div> </div> <div class="carousel-item"> <!--Mask color--> <div class="view hm-white-slight"> <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(151).jpg" alt="Second slide"> <div class="mask"></div> </div> <div class="carousel-caption"> <h3 class="h3-responsive">Second title</h3> <p>Second text</p> </div> </div> <div class="carousel-item"> <!--Mask color--> <div class="view hm-white-slight"> <img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(152).jpg" alt="Third slide"> <div class="mask"></div> </div> <div class="carousel-caption"> <h3 class="h3-responsive">Third title</h3> <p>Third text</p> </div> </div> </div> <!--/.Slides--> <!--Controls--> <a class="carousel-control-prev" href="#carousel-example-2" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#carousel-example-2" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> <!--/.Controls--> </div> <!--/.Carousel Wrapper-->
STEP 2: In home controller, create a ViewBag property isHome and set true.
public ActionResult Index(int? page) { ViewBag.isHome = true; models db = new models(); var courses = (from video in db.Courses orderby video.CourseId descending select video); int maxRows = 10; int pageNumber = (page ?? 1); return View(courses.ToPagedList(pageNumber, maxRows)); }
STEP 3:_Layout.cshtml
@if (ViewBag.isHome != null) { if (ViewBag.isHome) { @Html.Partial("_Slider") } }
VIDEO GUIDE:
Post your comments / questions
Recent Article
- ValueError:All arrays must be of the same length - Python
- Check hostname requires server hostname - SOLVED
- How to restrict access to the page Access only for logged user in Django
- Migration admin.0001_initial is applied before its dependency admin.0001_initial on database default
- Add or change a related_name argument to the definition for 'auth.User.groups' or 'DriverUser.groups'. -Django ERROR
- Addition of two numbers in django python
- The request was aborted: Could not create SSL/TLS secure channel -Error in Asp.net
- FieldError: Cannot resolve keyword 'id' into field in Django project
Related Article