簡體   English   中英

Asp.net Mvc3 PartialView

[英]Asp.net Mvc3 PartialView

我想在我的網站中有動態類別,在“管理”區域中添加類別,並在主頁中顯示為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>

我不確定上面的代碼,也不知道如何緩存Category,謝謝有人幫我,謝謝

不確定您真正想要的是什么,但是請看一下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()
{
}

不知道這是否回答了您的問題,但可以給它們分配一個鏈接,只需使用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);
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM