简体   繁体   中英

AutoSwitch Two Views in Asp.Net MVC

Is it possible to display two views in fixed interval ie 5 seconds or any time? So that I want to display two views from the same. How can I make it possible either via route config or via action method in the controller. I want to display the below action view in the interval of fixed time.

public ActionResult FlightBoardingDisplay()
{
    return View(db.tblFlightSchedules.OrderBy(m => m.Time).Where(m => m.Origin == "KATHMANDU").ToList());
}

public ActionResult FlightStatusDisplay()
{

    return View(db.tblFlightSchedules.OrderBy(m => m.Time).Where(m => m.Origin == "KATHMANDU").Where(m => m.FSId == 4).Where(m=>m.FSId ==1).Where(m=>m.FSId==3).ToList());
}

You can do this something like to call action method after some interval.The FlightBoardingDisplay View type must be Partial View

<script>
  window.onload=function(){
setTimeout(function(){ callFlightStatusDisplay(); callFlightBoardingDisplay(); }, 
 3000);
 }


   function callFlightStatusDisplay()
   {
  $.ajax({
   type: "GET",
  url: '@Url.Action("FlightStatusDisplay", "ControllerName")',
  contentType: "application/json; charset=utf-8",

  dataType: "json",
  success: function(data) { alert('Success'); 
     $('#DIVIDTOINSERTRESPONSE').html(data);
  },
  error: function() { alert('A error'); }
    });
 }

  function callFlightBoardingDisplay()
  {
  $.ajax({
   type: "GET",
   url: '@Url.Action("FlightBoardingDisplay", "ControllerName")',
   contentType: "application/json; charset=utf-8",
   dataType: "json",
   success: function(data) { alert('Success'); 
     $('#DIVIDTOINSERTRESPONSE').html(data);
   },
   error: function() { alert('A error'); }
     });
   }
 </script>

Controller

       [HttpGet]
       public ActionResult FlightBoardingDisplay()
      {
        string date = String.Format("{0:D}", DateTime.Now.Date);
        ViewBag.Date = date;

        return PartialView(db.tblFlightSchedules.OrderBy(m => m.Time).Where(m => m.Origin == 
        "KATHMANDU").ToList());
   }

[HttpGet]
public ActionResult FlightStatusDisplay()
{
    string date = String.Format("{0:D}", DateTime.Now.Date);
    ViewBag.Date = date;

    return PartialView(db.tblFlightSchedules.OrderBy(m => m.Time).Where(m => m.Origin == "KATHMANDU").Where(m => m.FSId == 4).Where(m=>m.FSId ==1).Where(m=>m.FSId==3).ToList());
}

Simply i find the solution by inserting

    <meta http-equiv="refresh" content="5;url=http://192.168.5.34:8084/FlightInfo/FlightBoardingDisplay" />

in both the views in the head section.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM