Partial Views Caching in ASP.NET MVC 3

后端 未结 1 1252
青春惊慌失措
青春惊慌失措 2020-12-10 14:15

How can I cache the output of the PartialViews in ASp.NET MVC 3? I know I can decorate the action with [OutputCache] attribute but what I just want to include the @OutputCac

相关标签:
1条回答
  • 2020-12-10 14:42

    This cannot be done. You need to use the Html.Action helper to render a child action decorated with the [OutputCache] attribute and which will render the partial.

    public class MyController : Controller
    {
        [OutputCache(Duration = 3600)]
        public ActionResult Index()
        {
            return View();
        }
    }
    

    and then include the partial:

    @model MvcApplication1.Models.someViewmodel
    @{
        ViewBag.Title = "Index";
    }
    <h2>Index</h2>
    @Html.Action("Index", "My")
    
    0 讨论(0)
提交回复
热议问题