I use the Razor viewer in ASP.Net MVC 3 RC 2. This is part of my city.cshtml
(for simplification in simple simplified code)
<div class="list"> @foreach(var product in SQL.GetProducts(Model.City) ) { <div class="product"> <div>@product.Name</div> <div class="category"> @foreach(var category in SQL.GetCategories(product.ID) ) { <a href="@category.Url">@category.Name</a> » } </div> </div> } </div>
I want to cache this part of my output using the OutputCache attribute, so I created a ProductList action with the OutputCache attribute enabled
<div class="list"> @Html.Action("ProductList", new { City = Model.City }) </div>
and I created a view in ProductList.cshtml as shown below
@foreach(var product in Model.Products ) { <div class="product"> <div>@product.Name</div> <div class="category"> @foreach(var category in SQL.GetCategories(product.ID) ) { <a href="@category.Url">@category.Name</a> » } </div> </div> }
but I still need to cache category output for each product. so I created a CategoryPath action with the OutputCache attribute enabled
@foreach(var product in Model.Products ){ <div class="product"> <div>@product.Name</div> <div class="category"> @Html.Action("CategoryPath", new { ProductID = product.ID }) </div> </div> }
But, apparently, this is not allowed. I got this error:
OutputCacheAttribute does not allow child actions that are children of an already cached child action.
I believe that they have a good reason why they should ban it. I really want this nested output caching.
Any idea of a workaround?
source share