title: MVC HTML.RenderAction – Error: Duration must be a positive number
body: <p>On my website I want the user to have the ability to login/logout from any page.  When the user select login button a modal dialog will be present to the user for him to enter in his credentials.</p>
  <p>Since login will be on every page, I thought I would create a partial view for the login and add it to the layout page.  But when I did this I got the following error:  <strong>Exception Details: System.InvalidOperationException: Duration must be a positive number.</strong></p>
  <p>There are other ways to work around this that would not using partial views, but I believe this should work.</p>
  <p>So to test this, I decided to make everything simple with the following code:</p>
  <p>Created a layout page with the following code</p>
  <pre><code>@{Html.RenderAction(&quot;_Login&quot;, &quot;Account&quot;);}
  </code></pre>
  <p>In the AccountController:</p>
  <pre><code>public ActionResult _Login()
  {
      return PartialView(&quot;_Login&quot;);
  }
  </code></pre>
  <p>Partial View _Login</p>
  <pre><code>&lt;a id=&quot;signin&quot;&gt;Login&lt;/a&gt;
  </code></pre>
  <p>But when I run this simple version this I still get this error:
  <strong>Exception Details: System.InvalidOperationException: Duration must be a positive number.</strong></p>
  <p>Source of error points to &quot;@{Html.RenderAction(&quot;_Login&quot;, &quot;Account&quot;);}&quot;</p>
  <p>There are some conversations on the web that are similar to my problem, which identifies this as bug with MVC (see links below). But the links pertain to Caching, and I'm not doing any caching.</p>
  <p>OuputCache Cache Profile does not work for child actions<br />
  <a href="http://aspnet.codeplex.com/workitem/7923" rel="noreferrer">http://aspnet.codeplex.com/workitem/7923</a></p>
  <p>Asp.Net MVC 3 Partial Page Output Caching Not Honoring Config Settings
  <a href="https://stackoverflow.com/questions/4797968/asp-net-mvc-3-partial-page-output-caching-not-honoring-config-settings/4800140#4800140">Asp.Net MVC 3 Partial Page Output Caching Not Honoring Config Settings</a></p>
  <p>Caching ChildActions using cache profiles won't work?
  <a href="https://stackoverflow.com/questions/4728958/caching-childactions-using-cache-profiles-wont-work/4869434#4869434">Caching ChildActions using cache profiles won&#39;t work?</a></p>
  <p>I'm not sure if this makes a difference, but I'll go ahead and add it here. I'm using MVC 3 with Razor.</p>
  <hr />
  <p>Update<br />
  Stack Trace</p>
  <pre><code>[InvalidOperationException: Duration must be a positive number.]
     System.Web.Mvc.OutputCacheAttribute.ValidateChildActionConfiguration() +624394
     System.Web.Mvc.OutputCacheAttribute.OnActionExecuting(ActionExecutingContext filterContext) +127
     System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +72
     System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +784922
     System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +314
     System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +784976
     System.Web.Mvc.Controller.ExecuteCore() +159
     System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
     System.Web.Mvc.&lt;&gt;c__DisplayClassb.&lt;BeginProcessRequest&gt;b__5() +62
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass1.&lt;MakeVoidDelegate&gt;b__0() +20
     System.Web.Mvc.&lt;&gt;c__DisplayClasse.&lt;EndProcessRequest&gt;b__d() +54
     System.Web.Mvc.&lt;&gt;c__DisplayClass4.&lt;Wrap&gt;b__3() +15
     System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +41
     System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +1363
  
  [HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.]
     System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +2419
     System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +275
     System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +94
     System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +838
     System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) +56
     ASP._Page_Views_Shared_SiteLayout_cshtml.Execute() in c:\Projects\prj Projects\prj\Source\Presentation\prj.PublicWebSite\Views\Shared\SiteLayout.cshtml:80
     System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
     System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +104
     System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +173
     System.Web.WebPages.WebPageBase.Write(HelperResult result) +89
     System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +234
     System.Web.WebPages.WebPageBase.PopContext() +234
     System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +384
     System.Web.Mvc.&lt;&gt;c__DisplayClass1c.&lt;InvokeActionResultWithFilters&gt;b__19() +33
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +784900
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +784900
     System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265
     System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +784976
     System.Web.Mvc.Controller.ExecuteCore() +159
     System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
     System.Web.Mvc.&lt;&gt;c__DisplayClassb.&lt;BeginProcessRequest&gt;b__5() +62
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass1.&lt;MakeVoidDelegate&gt;b__0() +20
     System.Web.Mvc.&lt;&gt;c__DisplayClasse.&lt;EndProcessRequest&gt;b__d() +54
     System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453
     System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +371
  </code></pre>
  <hr />
  <p>Update<br />
  When I Break in Code, it errors at  @{Html.RenderAction(&quot;_Login&quot;, &quot;Account&quot;);}  with the following exception.  The inner exception</p>
  <pre><code>Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.
      
  at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
     at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage)
     at System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm)
     at System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter)
     at System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues)
     at ASP._Page_Views_Shared_SiteLayout_cshtml.Execute() in c:\Projects\prj Projects\prj\Source\Presentation\prj.PublicWebSite\Views\Shared\SiteLayout.cshtml:line 80
     at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
     at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
     at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
     at System.Web.WebPages.WebPageBase.Write(HelperResult result)
     at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body)
     at System.Web.WebPages.WebPageBase.PopContext()
     at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
     at System.Web.Mvc.ControllerActionInvoker.&lt;&gt;c__DisplayClass1c.&lt;InvokeActionResultWithFilters&gt;b__19()
     at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
  </code></pre>
  <p><img src="https://i.stack.imgur.com/erXOV.jpg" alt="enter image description here" /></p>
  <hr />
  <p>Answer
  Thanks  Darin Dimitrov</p>
  <p>Come to find out, my AccountController had the following attribute</p>
  <blockquote>
  <p>[System.Web.Mvc.OutputCache(NoStore =true, Duration = 0, VaryByParam = &quot;*&quot;)].</p>
  </blockquote>
  <p>I don't believe this should caused a problem, but when I removed the attribute everything worked.</p>
  <p>BarDev</p>