Partial Page Caching and VaryByParam in ASP.NET MVC 3

后端 未结 1 737
不知归路
不知归路 2020-12-24 14:07

I\'m attempting to use the new partial page caching available in ASP.NET MVC 3. In my view, I\'m using:

<% Html.RenderAction(\"RenderContent\", Model); %         


        
1条回答
  •  离开以前
    2020-12-24 14:22

    I think I figured it out. It looks like the issue is that VaryByParam, when the input parameter is an object, uses ToString() on that object to determine it's uniqueness. So this leaves two options:

    1. Overriding ToString() to provide a unique identifier.
    2. Passing a unique identifier as an additional parameter:

      <% Html.RenderAction("RenderContent", Model, Model.Id); %>
      
      [Authorize]
      [OutputCache(Duration = 6000, VaryByParam = "id", VaryByCustom = "browser")]
      public ActionResult RenderContent(Content content, string id)
      {
         return PartialView(content);
      }
      

    0 讨论(0)
提交回复
热议问题