在一个控制器中交换两个视图

时间:2016-08-23 09:09:01

标签: c# asp.net-mvc views

我有一个查询:如何逐个从同一个控制器调用两个不同的视图。在20秒后,我希望我的视图能够改变。 ie(在下面的代码片段中查看Show Show with Swatch Show2,反之亦然)

//public ActionResult Index()
//{
//    return View(dc.ptcl.ToList());
//}

public ActionResult Create()
{
    return View();
}

public ActionResult Show()
{
    Query q = new Query();
    DBConnection.Open();
    string myQuery = q.getQuery();
    OdbcCommand cmd = DBConnection.CreateCommand();
    cmd.CommandText = myQuery;
    OdbcDataReader DbReader = cmd.ExecuteReader();
    DbReader.Read();
    int i = DbReader.FieldCount;

 //  string dummyResult = DbReader["LoggedInAgents"].ToString();
   // String fName = DbReader.GetName(1);
    String fName = DbReader.GetString(2);

   // ViewBag.Name = dummyResult;
    ViewBag.City = fName;
    ViewBag.Age = ViewBag.Age;
    ViewBag.Time = DateTime.Now.ToString("h:mm:ss tt");
    ViewBag.viewName = 0;
    DbReader.Close();
    cmd.Dispose();
    DBConnection.Close();
    Response.AddHeader("Refresh", "5");
    //int turnValue = 0;
    //if (turnValue == 0)
    //{
    //    turnValue = 1;
    //    return RedirectToAction("Show2", "Driver");

    //}

    //    System.Threading.Thread.Sleep(5000);
        return View();

}



public ActionResult Show2()
{

    ViewBag.loggedInAgents = "Lahore";

    ViewBag.onCalls = "Lahore";

    ViewBag.agentsInReady = "Lahore";

    ViewBag.agentsInNotReady = "Lahore";

    ViewBag.agentsInWrapUp = "Lahore";

    ViewBag.reservedAgents = "Lahore";

    ViewBag.callsOffered = "Lahore";

    ViewBag.callsAnswered = "Lahore";

    ViewBag.callsAbandoned = "Lahore";

    ViewBag.callsInQueue = "Lahore";

    ViewBag.longestTalkDuration = "Lahore";

    ViewBag.abandoned = "Lahore";

    ViewBag.serviceLevel = "Lahore";

    ViewBag.maxTimeInQueue =  DateTime.Now.ToString("h:mm:ss tt");
    return View();
}




// POST: /Service/Create
//[HttpPost]
//[ValidateAntiForgeryToken]
//public ActionResult Create([Bind(Include = "id,CustomerName,Age")] PtclData service)
//{
//    if (ModelState.IsValid)
//    {

//            dc.ptcl.Add(service);
//            dc.SaveChanges();

//    }
//    return RedirectToAction("Index");
//}

1 个答案:

答案 0 :(得分:0)

将此脚本添加到视图顶部,并将“Home”替换为您的控制器名称:

<script type="text/javascript">
    setInterval(function ()
    {
        window.location = "@Url.Action("Show2","Home")"
    }, 20000);
</script>