Note that there are some explanatory texts on larger screens.

plurals
  1. PONested partial output caching in ASP.NET MVC 3
    primarykey
    data
    text
    <p>I am using Razor view engine in ASP.Net MVC 3 RC 2. This is part of my view <code>city.cshtml</code></p> <p><strong>(drastically simplified code for the sake of simplicity in example)</strong></p> <pre><code>&lt;!-- in city.cshtml --&gt; &lt;div class="list"&gt; @foreach(var product in SQL.GetProducts(Model.City) ) { &lt;div class="product"&gt; &lt;div&gt;@product.Name&lt;/div&gt; &lt;div class="category"&gt; @foreach(var category in SQL.GetCategories(product.ID) ) { &lt;a href="@category.Url"&gt;@category.Name&lt;/a&gt; » } &lt;/div&gt; &lt;/div&gt; } &lt;/div&gt; </code></pre> <p>I want to cache this part of my output using OutputCache attribute, so I created an action <code>ProductList</code> with <code>OutputCache</code> attribute enabled</p> <pre><code>&lt;!-- in city.cshtml --&gt; &lt;div class="list"&gt; @Html.Action("ProductList", new { City = Model.City }) &lt;/div&gt; </code></pre> <p>and I created the view in <code>ProductList.cshtml</code> as below</p> <pre><code>&lt;!-- in ProductList.cshtml --&gt; @foreach(var product in Model.Products ) { &lt;div class="product"&gt; &lt;div&gt;@product.Name&lt;/div&gt; &lt;div class="category"&gt; @foreach(var category in SQL.GetCategories(product.ID) ) { &lt;a href="@category.Url"&gt;@category.Name&lt;/a&gt; » } &lt;/div&gt; &lt;/div&gt; } </code></pre> <p>but I still need to cache the <strong>category path</strong> output on each product. so I created an action <code>CategoryPath</code> with <code>OutputCache</code> attribute enabled</p> <pre><code>&lt;!-- in ProductList.cshtml --&gt; @foreach(var product in Model.Products ){ &lt;div class="product"&gt; &lt;div&gt;@product.Name&lt;/div&gt; &lt;div class="category"&gt; @Html.Action("CategoryPath", new { ProductID = product.ID }) &lt;/div&gt; &lt;/div&gt; } </code></pre> <p>But apparently this is not allowed. I got this error:</p> <blockquote> <p>OutputCacheAttribute is not allowed on child actions which are children of an already cached child action.</p> </blockquote> <p>I believe they have a good reason why they need to disallow this. I really want this kind of <em>nested Output Caching</em>.</p> <p>Any idea for a workaround?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload