0

我想在我的网站中有动态类别,在管理区域添加类别并在主页中显示为部分视图,很明显我应该缓存它,我的类别操作是这样的:

 public ActionResult Category()
        {

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

我的部分视图是:

@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 ,请有人帮助我,谢谢

4

2 回答 2

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()
{
}
于 2013-02-10T13:41:30.360 回答
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);
        }
于 2013-02-10T15:50:56.683 回答