我的视图中有一个辅助方法,它动态呈现整个表单。现在我想添加对 Asp.Net MVC RC 2 中可用的客户端验证的支持。
以下是我用来将验证摘要字段呈现到表单上的代码。
_viewPage.Html.EnableClientValidation();
MvcHtmlString validationSummary = _viewPage.Html.ValidationSummary("There are errors on this form. Please contact your administrator.");
if (validationSummary != null && validationSummary.ToString() != "")
Response.Write(validationSummary.ToString());
当代码达到这一点时,我得到以下错误。
System.Collections.Generic.KeyNotFoundException was unhandled by user code
Message="给定的键不在字典中。" Source="System" StackTrace:在 System.Collections.Generic.SortedDictionary 的 System.ThrowHelper.ThrowKeyNotFoundException()2.get_Item(TKey key)
at System.Web.Mvc.Html.ValidationExtensions.ValidationSummary(HtmlHelper htmlHelper, Boolean excludePropertyErrors, String message, IDictionary
2 htmlAttributes) 在 System.Web.Mvc.Html.ValidationExtensions.ValidationSummary(HtmlHelper htmlHelper, String message, IDictionary`2 htmlAttributes) 在 D:\EBS\Project.Fusion 的 Fusion.UI.MvcWebUX.Helper.FormGenerator.GenerateFormValidation() \Fusion.UI.MvcWebUX\Helper\FormGenerator.cs:D:\EBS\Project.Fusion\Fusion.UI.MvcWebUX\Helper\FormGenerator.cs 中 Fusion.UI.MvcWebUX.Helper.FormGenerator.GenerateForm() 的第 88 行:D:\EBS\Project.Fusion\Fusion.UI.MvcWebUX\Helper\FormGenerator.cs 中 Fusion.UI.MvcWebUX.Helper.FormGenerator.RenderForm(ViewPage viewPage) 的第 70 行:ASP.views_shared_autoview_aspx.__RenderContent2 的第 60 行( HtmlTextWriter __w, Control parameterContainer) 在 d:\EBS\Project.Fusion\Fusion.UI.MvcWebUX\Views\Shared\AutoView.aspx: System.Web.UI.Control 的第 7 行。RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.Control.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter 适配器)在 System.Web.UI.Control.RenderControl(HtmlTextWriter writer)在 System.Web.UI.Control.RenderControl(HtmlTextWriter writer,ControlAdapter 适配器)在 ASP.views_shared_fusion_master.__Render__control1(HtmlTextWriter __w,Control parameterContainer)在 d: \EBS\Project.Fusion\Fusion.UI.MvcWebUX\Views\Shared\Fusion.Master:System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,ICollection children)的第 74 行,位于 System.Web.UI.Control.RenderChildren (HtmlTextWriter 作家)在 System.Web.UI.Control。在 System.Web.UI.Control.RenderControl(HtmlTextWriter writer,ControlAdapter 适配器)在 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer,ControlAdapter 适配器)在 System.Web.UI.Control.RenderControl( HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.Page.Render(HtmlTextWriter writer) at System .Web.Mvc.ViewPage.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web .UI.Control。System.Web.UI.Page.ProcessRequestMain 处的 RenderControl(HtmlTextWriter writer)(布尔 includeStagesBeforeAsyncPoint,布尔 includeStagesAfterAsyncPoint)InnerException:
我已经为此苦苦挣扎了几个小时。谁能帮我解决它并告诉我为什么会发生这种情况。