简体   繁体   English

Asp.net Mvc3 PartialView

[英]Asp.net Mvc3 PartialView

I wanna to have dynamic categories in my web site, Adding category in Admin area and show as a partialView in main page , it is clear that I should cache that , my category action is like this : 我想在我的网站中有动态类别,在“管理”区域中添加类别,并在主页中显示为partialView,很明显,我应该缓存该类别,我的类别操作如下所示:

 public ActionResult Category()
        {

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

and my partialView is : 我的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>

I'm not sure about above code and also have no idea about how to cache Category , please someone help me about that,thanks 我不确定上面的代码,也不知道如何缓存Category,谢谢有人帮我,谢谢

Not sure what you really want, but have a look at OutputCache - http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/improving-performance-with-output-caching-cs 不确定您真正想要的是什么,但是请看一下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()
{
}

Not sure if this answers you question or not but to assign them a link just use Html.ActionLink() then have an action that take the selected category id as a parameter and loads a detailed view of the 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