我有以下操作方法: -爲什麼我收到「時長必須爲正數。」,定義CacheProfile時
[HttpGet]
[OutputCache(CacheProfile = "long", Location = OutputCacheLocation.Server, VaryByHeader = "X-Requested-With")]
public PartialViewResult LatestAssets()
{
var tech = repository.LatestTechnology().OrderByDescending(a => a.TechnologyID).Take(5).ToList() ;
return PartialView("_Latest",tech);
}
這是通過下面的代碼_layout視圖中呼籲: -
<li class="nav-header hidden-tablet"style="background-color:#3E9BD4 ; color:white">Latest Assets</li>
@Html.Action("LatestAssets","Home")
緩存配置文件被定義在web.config如下內: -
<system.web>
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="long" duration="300" />
<add name="Short" duration="100" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
,但我得到的FOL降脂代碼時的操作方法被稱爲: -
Duration must be a positive number. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Duration must be a positive number
如果我刪除CacheProfile以上將正常工作。 任何想法是什麼導致此錯誤。
可能重複的[MVC HTML.RenderAction - 錯誤:持續時間必須是正數](http://stackoverflow.com/questions/4997989/mvc-html-renderaction-error-duration-must-bea-a-正數) –
ChildActions的'OutputCache'不符合配置文件的持續時間設置。您可以繞過它創建一個自定義的OutputCache屬性來讀取您的配置文件設置。這是如何:http://stackoverflow.com/a/13866280/1373170 –