views:

337

answers:

1

After upgrading an application from ASP.NET MVC 1 to ASP.NET MVC 2 RC cache substitution has stopped working.

This is my action:

 [OutputCache(Duration = 30, VaryByParam = "none")]
 public ActionResult CacheTest1()
 {
      return View("CacheTest");
 }

This is the Substitute extensions:

public static object Substitute(this HtmlHelper html, MvcCacheCallback cb)
{
    html.ViewContext.HttpContext.Response.WriteSubstitution(
        c => cb(new HttpContextWrapper(c)));
    return null;
}

And this is my view:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CacheTest</title>
</head>
<body>
    <div>
    Date: <%=DateTime.Now.ToString() %>
    Substitute: <%=Html.Substitute(c => DateTime.Now.ToString()) %>
    Response.WriteSubstitution: <% Response.WriteSubstitution(c => DateTime.Now.ToString()); %>
    </div>
</body>
</html>

The page is cached for a minute and substitution does not work, it just shows the time when the page was initially rendered. That was working in ASP.NET MVC 1.0!!

Any ideas?

Thanks

+1  A: 

This is specification, written at release note.

The Html.Substitute helper method in MVC Futures is no longer available

Due to changes in the rendering behavior of MVC view engines, the Html.Substitute helper method does not work and has been removed.

takepara
Thank you. I've already read that. I expected that even if Html.Substitute was no longer available, I could achieve the same effect using another solution.
Richard Chamorro
Is this ultimate response?
Jenea
Any update on this? Alternate solutions?
James Santiago