您可以改爲使用RenderAction。例如:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
return View();
}
[OutputCache(Duration = 6000, VaryByParam = "none")]
public ActionResult Cached()
{
// You could return whatever you want here, even a view
// but for the purpose of the demonstration I am simply
// returning a dynamic string value
return Content(DateTime.Now.ToLongTimeString(), "text/html");
}
}
和內部Index.cshtml
和About.cshtml
的觀點,你可以包括子操作:
<div>
@{Html.RenderAction("Cached");}
</div>
它,你會得到它的緩存版本在兩個頁面。
謝謝Darin。那很完美。而不是返回內容我執行返回PartialView(對象);正如你在筆記中提到的那樣。 – 2011-03-04 17:42:32
Darin,你知道有什麼方法讓OutputCache在使用局部視圖時使用緩存配置文件嗎? – 2011-08-21 00:30:27
@Mark好,不支持。你可以看看下面的文章,它解釋了這個問題:http://www.dotnetcurry.com/ShowArticle.aspx?ID=665。您可以編寫自定義操作過濾器來修復它。 – 2011-08-21 14:47:51