ASP.NET MVC 2 disables cache for browser back button in partial view

I use Html.RenderAction<CartController>(c => c.Show());on my main page to display a cart for all pages. The problem is when I add an item to the cart and then remove the back button. It shows the old cart (from the cache) until I click the refresh button or go to another page.

I tried this one and it works fine, but it disables the cache globally for the entire page and for all pages of my site (since this action method is used on the main page). I need to enable the cache for several other partial representations (action methods) for performance reasons.

I would not want to use the client side of the script with AJAX to update the cart (and login) when the page loads - but this is the only solution I can think of right now.

Does anyone know better?

+5
source share
2 answers

If you are not using iframe or ajax, it is not possible to disable the browser cache for only part of the page. The browser simply retrieves the data from the cache and disables the page cache or not.

+1
source

Hole caching in ASP.NET MVC

, . , . .

<%@ Control Language="C#" Inherits="ViewUserControl<IEnumerable<Joke>>" %>
<%@ OutputCache Duration="100" VaryByParam="none" %>

<ul>
<% foreach(var joke in Model) { %>
    <li><%= Html.Encode(joke.Title) %></li>
<% } %>
</ul>

Haacked .

, .

+1

All Articles