【问题标题】:Data source not bound error in MVC 4 WebGrid upon refresh. TempData reseting刷新时 MVC 4 WebGrid 中的数据源未绑定错误。 TempData 重置
【发布时间】:2014-01-09 03:57:38
【问题描述】:

我有一个 MVC 4 应用程序,它显示 WebGrid 中的搜索结果列表。结果页面正确加载,显示与搜索匹配的所有数据。如果我重新加载我得到的页面......

"A data source must be bound before this operation can be performed."

我没有显示 WebGrid 是一个局部视图,因为我已经看到与局部视图相关的与此类似的问题。任何人都知道为什么刷新会导致数据丢失?

编辑:

这是我的结果页面的控制器方法。

public ActionResult Results()
    {
        var model = TempData["Results"] as List<iCap.Business.Complaint>;

        return View(model);
    }

我注意到 TempData["Results"] 在刷新时重置。有没有办法防止这种情况发生?

永远感谢,

摇滚

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4 webgrid tempdata


    【解决方案1】:

    在这里找到了我的问题的答案:https://stackoverflow.com/a/11194300/2682614。 TempData 会在刷新时重置,所以我现在改用 seesion。

    [HttpPost]
        public ActionResult Index(SearchView search)
        {
            Session["Results"] = null;
            var results = RCCADao.RCCASearch(search);
            Session["results"] = results;
    
            return RedirectToAction("Results");
        }
    
        public ActionResult Results()
        {
            var model = Session["Results"] as List<iCap.Business.Complaint>;
    
            return View(model);
        }
    

    希望这可以帮助其他有类似问题的人!

    摇滚

    【讨论】:

      猜你喜欢
      • 2016-07-20
      • 2011-05-05
      • 2019-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-23
      • 1970-01-01
      相关资源
      最近更新 更多