2011-02-10 93 views
1

这对我来说真的没有任何意义。Asp.Net MVC3 EditorFor Exception

我有与此字段的图模型中它:

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")] 
[DataType(DataType.Date)] 
public DateTime Scheduled { get; set; } 

我然后显示在视图中该字段(这是一个编辑视图)所示:

@Html.EditorFor(m=>m.Scheduled) 

第一次经过一个干净/重建循环后,它工作正常,它只显示框中的日期(我已经做了很多摆弄最近找出一个好方法,让它不显示在框中的日期和时间,这似乎最好的办法)。

但是,一旦我刷新页面,我得到如下:

值不能为空。 参数名称:流

描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。

异常详细信息:System.ArgumentNullException:值不能为空。 参数名称:流

并且此错误持续到另一个清理/重建循环。堆栈跟踪似乎表明视图引擎正试图从/ Shared/EditorTemplates目录加载模板。我没有这个模板,因为文档似乎表明它应该默认为文本框,这正是我想要的。

我没有使用直的TextBoxFor,因为它没有做格式化,EditorFor似乎这样做。当我试图制作一个模板来满足这个例外时,我又回到了试图弄清如何在视图中格式化日期的问题。

所以,我想有两件事情可以解答:为什么这个错误只发生在第一次刷新之后,或者如何在剃刀视图内格式化日期。

每请求,完整的堆栈:

[ArgumentNullException:值不能为空。 参数名称:流] System.IO.StreamReader..ctor(流流,编码的编码,布尔detectEncodingFromByteOrderMarks,的Int32 BUFFERSIZE)9496369 System.Web.UI.TemplateParser.ParseFile(字符串physicalPath,VirtualPath virtualPath)232 System.Web.UI.TemplateParser.ParseInternal()86 System.Web.UI.TemplateParser.Parse()160 System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType()110 System.Web.Compilation.BuildProvider。 GetCompilerTypeFromBuildProvider(BuildProvider buildProvider)+65 System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()+218 System.Web.Compilation.BuildProvidersCompiler.PerformBuild()+40 System.Web.Com System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(虚拟路径virtualPath,布尔noBuild,布尔allowCrossApp,布尔allowBuildInPrecompile,布尔throwIfNotFound,布尔ensureIsUpToDate)+320 System.Web.Compilation.BuildManager 。GetVPathBuildResultWithNoAssert(HttpContext上下文,虚拟路径virtualPath,布尔noBuild,布尔allowCrossApp,布尔allowBuildInPrecompile,布尔throwIfNotFound,布尔ensureIsUpToDate)+111 System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath,HttpContext上下文,布尔allowCrossApp,布尔throwIfNotFound)+125 System.Web.Compilation.BuildManager.GetCompiledType(VirtualPath virtualPath)+10 System.Web.Compilation.BuildManager.GetCompiledType(String virtualPath)+28 System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.GetCompiledType (String virtualPath)+7 System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext,TextWriter writer)+58 System.Web.Mvc.Html.TemplateHelpers.ExecuteTemplate(HtmlHelper html,ViewDataD字段viewData,字符串templateName,DataBoundControlMode模式,GetViewNamesDelegate getViewNames,GetDefaultActionsDelegate getDefaultActions)+584 System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html,ModelMetadata元数据,字符串htmlFieldName,String templateName,DataBoundControlMode模式,Object additionalViewData,ExecuteTemplateDelegate executeTemplate )+1027 System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html,ModelMetadata元数据,String htmlFieldName,String templateName,DataBoundControlMode模式,Object additionalViewData)+66 System.Web.Mvc.Html.TemplateHelpers.TemplateFor(HtmlHelper 1 html, Expression 1 expression,String templateName,String htmlFieldName,DataBoundControlMode mode,Object additionalViewData,TemplateHelperDelegate templateHelper)+118 System.Web.Mvc.Html.TemplateHelpers.Templ ateFor(的HtmlHelper 1 html, Expression 1的表达,字符串TEMPLATENAME,字符串htmlFieldName,DataBoundControlMode模式,对象additionalViewData)100 System.Web.Mvc.Html.EditorExtensions.EditorFor(的HtmlHelper 1 html, Expression 1表达)57 ASP._Page_Views_Visit_visit_Edit_cshtml.Execute()中d:\ Code ... \ Views \ Visit \ Visit \ Edit.cshtml:34 System.Web.WebPages.WebPageBase.ExecutePageHierarchy()+207 System.Web.Mvc.WebViewPage.ExecutePageHierarchy()+81 系统。 Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext,TextWriter writer,WebPageRenderingBase startPage)+76 System.Web.Mvc.RazorView.RenderView(ViewContext viewContext,TextWriter writer,Object instance)+220 System.Web.Mvc.BuildManagerCompiledView。渲染(V System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext上下文)+303 System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext,ActionResult actionResult)+13 System.Web.Mvc。 <> C_ DisplayClass1c.b _19()23 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter滤波器,ResultExecutingContext preContext,函数功能1 continuation) +260 System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList 1个过滤器,的ActionResult的ActionResult)177 System.Web.Mvc.ControllerActionInvoker.InvokeAction (ControllerContext controllerContext,String actionName)+343 System.Web.Mvc.Controller.ExecuteCore()+116 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)+97 System.Web.Mvc.ControllerBase.System。 Web.Mvc.IController.Execute(RequestContext requestContext)+10 System.Web.Mvc。 <> c_ DisplayClassb.b _5()+37 System.Web.Mvc.Async。 <> c_ DisplayClass1.b _0()+21 System.Web.Mvc.Async。 <> c_ DisplayClass8 1.<BeginSynchronous>b__7(IAsyncResult _) +12 System.Web.Mvc.Async.WrappedAsyncResult 1.End()+62 System.Web.Mvc。 <> c _DisplayClasse.b_ d()+50 System.Web.Mvc.SecurityUtil.b _0(Action f)+7 System.Web.Mvc。SecurityUtil.ProcessInApplicationTrust(动作动作)+22 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult的asyncResult)+60 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult的结果)+9 系统。 Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()8841105 System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔& completedSynchronously)184

+1

什么是堆栈跟踪? – SLaks 2011-02-10 05:30:12

回答

0

这使得甚至更小的感觉。为了提供进一步的细节,我启动了ProcMon,并开始考虑它尝试访问磁盘的内容,如果有的话。我注意到它试图读取模板文件夹下不存在的__MVCSITEMAPPROVIDER。

知道我在使用MvcSiteMapProvider库的一个稍微有点非标准的版本(我手动升级到MVC3),我决定从codeplex中获取最新版本。丢弃它,清洁&重建,它甚至在刷新后仍然有效。

问题是解决了,但我仍然不知道为什么它只是工作在第一负载干净后&重建。根据procmon,它仍然试图访问__MVCSITEMAPPROVIDER在第一次加载,但它的工作。