c# - Can PagedList be used to automatically switch pages? -


i using asp.net-mvc , have pagelist https://github.com/troygoode/pagedlist in project, works fine able switch pages automatically on set time interval. pages using have set number of accordion items , wanted know how switch page number without human interaction. use slideshow pagedlist. there better use or possible?

my index.cshtml

@model pagedlist.ipagedlist<computerdowntimetracker.models.dashboardticketlistvm> @using pagedlist.mvc; <body>  <div class="list1">     <div id="accordion">          @foreach (var item in model)         {            <div class="header">                  <b> equipment: </b>@item.computername <br />                 <b> location: </b>@item.location                  @switch (item.runningstatus)                 {                     case 1: imagepath = down;                         break;                     case 2: imagepath = running;                         break;                     case 3: imagepath = waiting;                         break;                     case 4: imagepath = waiting;                         break;                     default: imagepath = running;                         break;                 }                 <img class="status" src="@imagepath" alt="" />                   <ul class="timestat">                      <li><b class="time">computer down @ :</b> @item.onclicktimestamp</li>                       @if (@item.runningstatus == 4)                     {                         <li> <b class="time"> maintenance on issue :</b> @item.edittimestamp</li>                     }                     @if (@item.runningstatus == 3)                     {                         <li> <b class="time">waiting parts :</b> @item.edittimestamp</li>                     }                     @if (@item.runningstatus == 2)                     {                         <li> <b class="time">computer restarted :</b> @item.edittimestamp</li>                     }                 </ul>              </div>@*//computer name , status div*@              <div><p>@html.raw(@item.computerstatus)</p></div>          }           @(model.pagecount < model.pagenumber ? 0 : model.pagenumber) of @model.pagecount         @html.pagedlistpager(model, page => url.action("index",new { page }))      </div>  </div> 

my home controller index method

    public actionresult index(int? page)     {         var time = datetime.now;         time = time.addseconds(-100);           var viewmodel = _computerdb.database.sqlquery<dashboardticketlistvm>(listquery).tolist();          var remove_running = viewmodel.where(x => x.onrestarttimestamp >= time || x.onrestarttimestamp == null);          int pagesize = 8;         int pagenumber = (page ?? 1);           return view("index", "~/views/shared/_listlayout.cshtml", remove_running.topagedlist(pagenumber, pagesize));     } 

i omitted lot of stuff wasn't relevant

you need use use javascript settimeout reload next page after specified time.

using pagedlist examples:

controller

public class productcontroller : controller {     public object index(int? page)     {         var products = myproductdatasource.findallproducts(); //returns iqueryable<product> representing unknown number of products. thousand maybe?          var pagenumber = page ?? 1; // if no page specified in querystring, default first page (1)         var onepageofproducts = products.topagedlist(pagenumber, 25); // contain 25 products max because of pagesize          viewbag.onepageofproducts = onepageofproducts;         return view();     } } 

view

@{     viewbag.title = "product listing" } @using pagedlist.mvc; //import our html helper @using pagedlist; //import can cast our list ipagedlist (only necessary because viewbag dynamic)  <!-- import included stylesheet (very basic) default styling --> <link href="/content/pagedlist.css" rel="stylesheet" type="text/css" />  <!-- loop through each of products , display want. we're printing name here --> <h2>list of products</h2> <ul>     @foreach(var product in viewbag.onepageofproducts){         <li>@product.name</li>     } </ul>  <!-- output paging control lets user navigation previous page, next page, etc --> @html.pagedlistpager( (ipagedlist)viewbag.onepageofproducts, page => url.action("index", new { page }) ) 

view javascript

<script type="text/javascript">     var nextpage = @(((ipagedlist)viewbag.onepageofproducts.pagenumber) + 1); // next page number current page number + 1     settimeout(function() {         window.location = "index?page=" + nextpage; // load new page after timeout     }, (5 * 1000) /* set timeout here, example: 5 seconds */); </script> 

note: may need add additional logic make sure stop next page loading whenever end of pages. can checked hasnextpage property provided pagedlist.

example:

<script type="text/javascript">     var hasnextpage = @(((ipagedlist)viewbag.onepageofproducts.hasnextpage) ? "true" : "false");      if(hasnextpage) {         var nextpage = @(((ipagedlist)viewbag.onepageofproducts.pagenumber) + 1); // next page number current page number + 1         settimeout(function() {             window.location = "index?page=" + nextpage; // load new page after timeout         }, (5 * 1000) /* set timeout here, example: 5 seconds */);     } </script> 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -