我对EditorFor有一个奇怪的看法。以下代码引发ArgumentNullException。
<%: Html.EditorFor(x => x.Name) %>
<%: Html.TextBoxFor(x => x.Name) %>
Name是一个字符串变量-它是设置好的。
EditorFor在另一个视图中工作-直到这个视图崩溃,此时我必须重新启动development web服务器(Cassini),否则所有EditorFor调用都将崩溃,并显示相同的消息。
我用MVC 2的源代码运行了一个测试,希望我能得到一些见解,但那没问题!估计那里的MVC 2 RTM源应该是VS2010中的一个(日期似乎是相互关联的)。
我刚转到了textbox,因为这很好-但我想知道问题是什么。我在.NET 4、VS2010和Win7 x64下运行。
更新
:DisplayFor也会出现同样的问题。]
部分堆栈跟踪是:
[ArgumentNullException: Value cannot be 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.GetVPathBuildResultWithNoAssert(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.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +52
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(String virtualPath, Type requiredBaseType) +28
System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.CreateInstanceFromVirtualPath(String virtualPath, Type requiredBaseType) +36
System.Web.Mvc.WebFormView.Render(ViewContext viewContext, TextWriter writer) +172
System.Web.Mvc.Html.TemplateHelpers.ExecuteTemplate(HtmlHelper html, ViewDataDictionary viewData, String templateName, DataBoundControlMode mode, GetViewNamesDelegate getViewNames) +1154
System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData, ExecuteTemplateDelegate executeTemplate) +1626
System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData) +86
System.Web.Mvc.Html.TemplateHelpers.TemplateFor(HtmlHelper`1 html, Expression`1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData, TemplateHelperDelegate templateHelper) +210
System.Web.Mvc.Html.TemplateHelpers.TemplateFor(HtmlHelper`1 html, Expression`1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData) +129
System.Web.Mvc.Html.EditorExtensions.EditorFor(HtmlHelper`1 html, Expression`1 expression) +87