代码之家  ›  专栏  ›  技术社区  ›  Maslow

ASP.NET MVC控制器索引方法在从其他控制器重定向时不会激发

  •  2
  • Maslow  · 技术社区  · 15 年前
    public ActionResult Index()
        {
    
            var tickets =
                DependencyContainer.DomainController.ShowTickets();
            if(tickets==null)
            {
                ViewData.Add("Error","Associate not found");
                return RedirectToAction("Index", "Home");//Doesn't fire the index?
            }
            return View();
    

    home controller方法如下所示,仅在调试器启动时激发,如果我点击了f5,则在重定向后激发。

        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to Home Loans and Insuring Technology Ticketing";
            //if (TempData.ContainsKey(ErrorKey))
            //{
            //    ViewData[ErrorKey] = TempData[ErrorKey];
            //    TempData.Remove(ErrorKey);
            //}
            return View();
        }
    

    重定向不会触发控制器?

    1 回复  |  直到 15 年前
        1
  •  0
  •   Craig Stuntz    15 年前
    1. 你必须使用 TempData 重定向时。 ViewData 不会工作 在重定向之前设置。
    2. 是否缓存网站索引?浏览器是否缓存它?用Firebug或Fiddler查看请求和响应。