繁体   English   中英

Asp.Net MVC3编辑器

[英]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:值不能为null。 参数名称:流

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

我没有使用直的TextBoxFor,因为它不进行格式化,而EditorFor似乎可以这样做。 当我尝试制作一个模板来满足此异常时,我又回到了试图弄清楚如何在视图中设置日期格式的问题。

因此,我想有两个方法可以解决问题:为什么仅在第一次刷新后才发生此错误,或者如何在Razor视图中格式化日期。

根据请求,完整堆栈:

[ArgumentNullException:值不能为null。 参数名称:流] System.IO.StreamReader..ctor(流流,编码编码,布尔型detectEncodingFromByteOrderMarks,Int32 bufferSize)+9496369 System.Web.UI.TemplateParser.ParseFile(字符串physicalPath,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.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)+8945798 System.Web.Compilation.BuildManager.GetVPathBuildResultInternal (VirtualPath virtualPath,布尔值noBuild,布尔值allowCrossApp,布尔值allowBuildInPrecompile,布尔值throwIfNotFound,布尔值sureIsUpToDate)+320 System.Web.Compilation.BuildManager.GetVP athBuildResultWithNoAssert(HttpContext上下文,VirtualPath virtualPath,布尔noBuild,布尔allowCrossApp,布尔allowBuildInPrecompile,布尔throwIfNotFound,布尔sureIsUpToDate)+111 System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath,HttpContext上下文,布尔allowCIfsApp, .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,ViewDataDictionary viewData,String templateName,DataBoundControlMode模式,GetViewNamesDelegate getViewNames,GetDefaultActionsDelegate) +584 System.Web.Mvc.Html.TemplateHelpers.TemplateHelper (HtmlHelper html,ModelMetadata元数据,字符串htmlFieldName,字符串templateName,DataBoundControlMode模式,对象AdditionalViewData,ExecuteTemplateDelegate executeTemplate)+1027 System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html,ModelMetadata元数据,字符串htmlFieldName,字符串templateName,DataBoundControlMode ,对象AdditionalViewData)+66 System.Web.Mvc.Html.TemplateHelpers.TemplateFor(HtmlHelper 1 html, Expression 1表达式,字符串templateName,字符串htmlFieldName,DataBoundControlMode模式,对象AdditionalViewData,TemplateHelperDelegate templateHelper)+118 System.Web.Mvc.Html .TemplateHelpers.TemplateFor(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()in d:\\ Code ... \\ Views \\ Visit \\ Visit \\ Edit.cshtml:34 Sy stem.Web.WebPages.WebPageBase.ExecutePageHierarchy()+207 System.Web.Mvc.WebViewPage.ExecutePageHierarchy()+ 81 System.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.Render(ViewContext viewContext,TextWriter writer)+115 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)+ 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,Func 1 continuation) +260 System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList 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系统。 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(动作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 System.Web.CallHandlerExec utionStep.System.Web.HttpApplication.IExecutionStep.Execute()+8841105 System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值和完成同步)+184

这更没有意义。 为了提供更多详细信息,我启动了ProcMon,并开始查看它在磁盘上尝试访问的内容(如果有)。 我注意到它试图读取模板文件夹下的__MVCSITEMAPPROVIDER,该文件夹不存在。

知道我使用的是MvcSiteMapProvider库的一个稍微有点错误的非标准版本(我手动将其升级到了MVC3),所以我决定从codeplex中获取最新版本。 将其放入,清理和重建,即使刷新后也可以使用。

问题已解决,但我仍然不知道为什么它在清理和重建后只能在第一次加载时工作。 根据procmon的说法,它仍在尝试在第一次加载时访问__MVCSITEMAPPROVIDER,但它可以工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM