[英]AutoSwitch Two Views in Asp.Net MVC
是否可以固定间隔(即5秒或任何时间)显示两个视图? 因此,我想显示来自同一视图的两个视图。 如何通过路由配置或控制器中的操作方法使之成为可能。 我想以固定的时间间隔显示以下操作视图。
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());
}
您可以执行一些操作,例如在一段时间间隔后调用操作方法。FlightBoardingDisplay视图类型必须为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>
控制者
[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());
}
我简单地通过插入找到解决方案
<meta http-equiv="refresh" content="5;url=http://192.168.5.34:8084/FlightInfo/FlightBoardingDisplay" />
在头部的两个视图中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.