asp.net-mvc – MVC HTML.RenderAction – 错误:持续时间必须是正数

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – MVC HTML.RenderAction – 错误:持续时间必须是正数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的网站上,我希望用户能够从任何页面登录/注销.当用户选择登录按钮时,将出现一个模态对话框,供用户输入他的凭据.

由于登录将在每个页面上,我以为我将创建一个部分的登录视图,并将其添加到布局页面.但是当我这样做我得到以下错误:异常详细信息:System.InvalidOperationException:持续时间必须是正数.

还有其他方法解决这个不会使用局部视图的方法,但我相信这应该是有效的.

所以要测试这个,我决定使用以下代码简化一切:

使用以下代码创建布局页面

@{Html.RenderAction("_Login","Account");}

在AccountController中:

public ActionResult _Login()
{
    return PartialView("_Login");
}

部分视图_Login

<a id="signin">Login</a>

但是,当我运行这个简单的版本,我仍然得到这个错误
异常详细信息:System.InvalidOperationException:持续时间必须是正数.

错误来源指向“@ {Html.RenderAction(”_ Login“,”Account“);}”

网络上有一些类似于我的问题的对话,它将这识别为MVC的bug(见下面的链接).但链接属于缓存,我没有进行任何缓存.

OuputCache缓存配置文件不适用于子操作
http://aspnet.codeplex.com/workitem/7923

Asp.Net MVC 3部分页输出缓存不符合配置设置
Asp.Net MVC 3 Partial Page Output Caching Not Honoring Config Settings

使用缓存配置文件缓存ChildAction将不起作用?
Caching ChildActions using cache profiles won’t work?

我不知道这是否有所作为,但我会继续添加.我在使用MVC 3与剃刀.

更新
堆栈跟踪

[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,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.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
   System.Web.Mvc.<>c__DisplayClass4.<Wrap>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,String queryStringOverride) +2419
   System.Web.HttpServerUtility.Execute(IHttpHandler handler,Boolean setPrevIoUsPage) +275
   System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler,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,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,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.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +33
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter,ResultExecutingContext preContext,Func`1 continuation) +784900
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter,Func`1 continuation) +784900
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext,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.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously) +371

更新
当我破解代码时,它会在@ {Html.RenderAction(“_ Login”,“Account”);}中出现错误,但有以下异常.内在的例外

Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.

at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler,String queryStringOverride)
   at System.Web.HttpServerUtility.Execute(IHttpHandler handler,Boolean setPrevIoUsPage)
   at System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler,Boolean preserveForm)
   at System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper,TextWriter textWriter)
   at System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper htmlHelper,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,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.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter,Func`1 continuation)

回答
谢谢Darin Dimitrov

来了解一下,我的AccountController具有以下属性

[System.Web.Mvc.OutputCache(NoStore =true,Duration = 0,VaryByParam = “*”)].

我不相信这应该是一个问题,但是当我删除属性一切工作.

BarDev

解决方法

添加我的评论作为答案:

嗯,这很奇怪通过阅读你的问题,我已经准备好打赌5块钱,你有缓存启用了某种方式.尝试重命名操作,控制器.确保您正在调用的操作不使用[OutputCache]属性进行装饰.尝试在一个从头开始的新项目中执行此操作.我相信你可以把它缩小.

原文链接:https://www.f2er.com/aspnet/250928.html

猜你在找的asp.Net相关文章