简体   繁体   English

Asp.Net MVC3编辑器

[英]Asp.Net MVC3 EditorFor Exception

This really makes no sense to me whatsoever. 这对我来说真的没有任何意义。

I have a view model with this field in it: 我有一个视图模型,其中包含此字段:

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

I then display this field in the view (this is an edit view) like this: 然后,我在视图(这是一个编辑视图)中显示此字段,如下所示:

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

The first time after a clean/rebuild cycle, it works fine, it displays just the date in the box (I've done lots of fiddling lately to figure out a good way to have it not display the date and time in the box, and this seems the best way). 清理/重建周期后的第一次,它可以正常工作,它只在框中显示日期(最近我做了很多摆弄,以找出一种不让它在框中显示日期和时间的好方法,这似乎是最好的方法)。

However, once I refresh the page, I get the following: 但是,刷新页面后,将得到以下信息:

Value cannot be null. 值不能为空。 Parameter name: stream 参数名称:流

Description: An unhandled exception occurred during the execution of the current web request. 说明:执行当前Web请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code. 请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。

Exception Details: System.ArgumentNullException: Value cannot be null. 异常详细信息:System.ArgumentNullException:值不能为null。 Parameter name: stream 参数名称:流

And this error persists until another clean/rebuild cycle. 并且此错误一直持续到另一个清理/重建周期。 The stack trace seems to indicate that the view engine is attempting to load the template from the /Shared/EditorTemplates directory. 堆栈跟踪似乎表明视图引擎正在尝试从/ Shared / EditorTemplates目录加载模板。 I have no template for this, since the documentation seems to indicate that it should default to a text box, which is what I want. 我没有模板,因为文档似乎表明它应默认为文本框,这正是我想要的。

I'm not using a straight TextBoxFor since it doesn't do the formatting, and EditorFor seems to do that. 我没有使用直的TextBoxFor,因为它不进行格式化,而EditorFor似乎可以这样做。 And when I try to make a template to satisfy this exception, I'm back at the issue of trying to figure out how to format the date in the view. 当我尝试制作一个模板来满足此异常时,我又回到了试图弄清楚如何在视图中设置日期格式的问题。

So, I suppose two things will work for an answer: Why this error is happening only after the first refresh, or how to format a date inside a Razor view. 因此,我想有两个方法可以解决问题:为什么仅在第一次刷新后才发生此错误,或者如何在Razor视图中格式化日期。

Per request, the full stack: 根据请求,完整堆栈:

[ArgumentNullException: Value cannot be null. [ArgumentNullException:值不能为null。 Parameter name: stream] System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize) +9496369 System.Web.UI.TemplateParser.ParseFile(String 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.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +8945798 System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +320 System.Web.Compilation.BuildManager.GetVP 参数名称:流] 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 context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +111 System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean 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, ViewDataDictionary viewData, String templateName, DataBoundControlMode mode, GetViewNamesDelegate getViewNames, GetDefaultActionsDelegate getDefaultActions) +584 System.Web.Mvc.Html.TemplateHelpers.TemplateHelper 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 metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData, ExecuteTemplateDelegate executeTemplate) +1027 System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, 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.TemplateFor(HtmlHelper 1 html, Expression 1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData) +100 System.Web.Mvc.Html.EditorExtensions.EditorFor(HtmlHelper 1 html, Expression 1 expression) +57 ASP._Page_Views_Visit_visit_Edit_cshtml.Execute() in d:\\Code...\\Views\\Visit\\Visit\\Edit.cshtml:34 Sy (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 filter, ResultExecutingContext preContext, Func 1 continuation) +260 System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList 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 filters, 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(Action action) +22 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 System.Web.CallHandlerExec 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 step, Boolean& completedSynchronously) +184 utionStep.System.Web.HttpApplication.IExecutionStep.Execute()+8841105 System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值和完成同步)+184

This makes even less sense. 这更没有意义。 In an attempt to provide further details, I fired up ProcMon, and started looking at what it was trying to access on disk, if anything. 为了提供更多详细信息,我启动了ProcMon,并开始查看它在磁盘上尝试访问的内容(如果有)。 I noticed it trying to read a __MVCSITEMAPPROVIDER under the templates folder, which didn't exist. 我注意到它试图读取模板文件夹下的__MVCSITEMAPPROVIDER,该文件夹不存在。

Knowing that I was using a slightly, erm, non-standard version of the MvcSiteMapProvider library (I upgraded it to MVC3 by hand), I decided to go get the latest version off of codeplex. 知道我使用的是MvcSiteMapProvider库的一个稍微有点错误的非标准版本(我手动将其升级到了MVC3),所以我决定从codeplex中获取最新版本。 Dropped it in, clean & rebuilt, and it works even after refreshes. 将其放入,清理和重建,即使刷新后也可以使用。

The problem is solved, but I still have no clue why it was only working on the first load after a clean & rebuild. 问题已解决,但我仍然不知道为什么它在清理和重建后只能在第一次加载时工作。 According to procmon, it was still trying to access __MVCSITEMAPPROVIDER on the first load, but it worked. 根据procmon的说法,它仍在尝试在第一次加载时访问__MVCSITEMAPPROVIDER,但它可以工作。

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

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