2011-04-05 71 views
2

現金下拉列表可能嗎?ASP.NET MVC:緩存組合框

我正在使用Telerik MVC窗口ComboBox,並且窗口(包括ComboBox)的內容正在以部分視圖返回。局部視圖的內容取決於參數列表,但在該窗口的每個div中都有一個組合框,其內容通常不變,並且包含〜2000條記錄。

我在考慮使用單獨的控制器與返回的窗口本身兌現之前返回計算機[「ComboContent」],但可能有一個更好的辦法...

TIA

更新(我控制器代碼):

 [AcceptVerbs("GET")] 
     [OutputCache(Duration = int.MaxValue, VaryByParam = "id")] //Some custom param?? 
     public ActionResult LoadTimeOffset(int id) 
     { 
      String error; 
      IEnumerable<MyModel> model = repo.GetSomeVariableStuff(id, 10, out error); //always varies 
      ViewData["ComboList"] = new SelectList(repo.GetComboitems(id), "Key", "Value", -1); //changes only on id 

      if (model.Count() > 0) 
      { 
       return PartialView("Partial", model); 
      } 

      return Content(error); 
     } 

回答

3

緩存數據而不是緩存下拉列表。

所以,與其把的SelectList到ViewData的,把內容吧:

if (HttpContext.Current.Cache["ComboList"] == null) 
{ 
    HttpContext.Current.Cache["ComboList"] = repo.GetComboitems(id); //use Add instead so that you can specify the cache duration. 
} 
ViewData["ComboList"] = HttpContext.Current.Cache["ComboList"]; //take from cache. 

注意,代碼是不準確的,但它僅僅是一個例子。

然後,在您的視圖中,呈現組合。

我希望這會有所幫助。