2013-02-10 96 views
0

我想要在我的網站中添加動​​態類別,在Admin區域添加類別並在主頁面中顯示爲partialView,很明顯我應該緩存該內容,我的類別操作如下所示:Asp.net Mvc3 PartialView

public ActionResult Category() 
     { 

      var category = _categoryRepository.GetAllCategory(); 
      return PartialView(category); 
     } 

和我partialView是:

@model IEnumerable<Blog.Domain.Model.Category> 
@{ 
    ViewBag.Title = "Category"; 
    Layout = null; 
} 
<div> 
    @foreach (var item in Model) 
    { 
     <ul> 
      @Html.DisplayFor(x => item.Name) 
     </ul> 
    } 
</div> 

我不知道上面的代碼,也沒有關於如何緩存類別的想法,請幫助我的人有關,由於

回答

0

不知道這是否回答您的問題或沒有,但給它們分配一個鏈接只需使用Html.ActionLink(),然後有采取選擇的動作類別ID作爲參數並加載類別的詳細視圖。

@model IEnumerable<Blog.Domain.Model.Category> 
    @{ 
     ViewBag.Title = "Category"; 
     Layout = null; 
    } 
    <div> 
     @foreach (var item in Model) 
     { 
      <ul> 
       @Html.ActionLink(item.Name, "Detail". "Category", new {id = item.id) 
      </ul> 
     } 
    </div> 

public ActionResult Details(int id) 
     { 

      var category = _categoryRepository.GetById(id); 
      //detail CategoryView 
      return PartialView(category); 
     } 
1

不肯定你真正想要的,但看看OutputCache - http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/improving-performance-with-output-caching-cs

[OutputCache(Duration=10, VaryByParam="none")] 
public ActionResult Category() 
{ 
} 
+0

感謝您的回答,但我的主要問題是關於動態類別,從Db中檢索類別並在partialview中顯示它並渲染局部佈局! – 2013-02-10 14:04:55

+0

@EricNielsen呃,什麼? – manojlds 2013-02-10 14:07:25

+0

每個網站都有一個類別列表,賴特?我有我的數據庫中的分類列表,並希望在partialView中顯示它們,這就是全部! – 2013-02-10 15:37:11