[英]ASP.Net MVC RC 2.0 Upgrade From MVC 2.0 Beta Validation Issue
我们刚刚升级了我们的应用程序,发现我们在所有Html.ValidationMessages和Html.ValidationMessageFor上都遇到了运行时错误。 错误是: 字典中没有给定的密钥。 我们一直在传递modelName / expression,它在升级之前工作正常。 我还检查了自述文件中描述的重大更改,但没有注意到与之相关的任何内容。
在调试ASP.NET MVC源代码后,我找到了导致此问题的原因。
你必须在<%Html.BeginForm%>之前有<%= Html.EnableClientSideValidation%>,原因是当启用客户端验证时,Html表单助手将生成一个使用的Id(formContext.FormId)在验证助手中。 这意味着如果要使用验证帮助程序,则必须使用内置表单帮助程序。
因此,要解决此问题,只需将<%= Html.EnableClientSideValidation%>移动到第一个表单上方,并确保使用Html.BeginForm帮助程序方法。
我在这里得到了同样的错误,Levi,我知道你在asp.net mvc团队,你能提供一些指导吗?
这是错误。
Line 185: // rules will already have been written to the metadata object
Line 186: fieldMetadata.ReplaceValidationMessageContents = (String.IsNullOrEmpty(validationMessage)); // only replace contents if no explicit message was specified
Line 187: fieldMetadata.ValidationMessageId = builder.Attributes["id"];
Line 188: }
Line 189:
这是痕迹。
[KeyNotFoundException: The given key was not present in the dictionary.]
System.ThrowHelper.ThrowKeyNotFoundException() +29
System.Collections.Generic.SortedDictionary`2.get_Item(TKey key) +5167507
System.Web.Mvc.Html.ValidationExtensions.ValidationMessageHelper(HtmlHelper htmlHelper, ModelMetadata modelMetadata, String expression, String validationMessage, IDictionary`2 htmlAttributes) in D:\Projects\Practice\Mercurial\onlinerestaurant\trunk\ReferenceProjects\aspnetmvc2-rc-sources\src\SystemWebMvc\Mvc\Html\ValidationExtensions.cs:187
System.Web.Mvc.Html.ValidationExtensions.ValidationMessageFor(HtmlHelper`1 htmlHelper, Expression`1 expression, String validationMessage, IDictionary`2 htmlAttributes) in D:\Projects\Practice\Mercurial\onlinerestaurant\trunk\ReferenceProjects\aspnetmvc2-rc-sources\src\SystemWebMvc\Mvc\Html\ValidationExtensions.cs:146
System.Web.Mvc.Html.ValidationExtensions.ValidationMessageFor(HtmlHelper`1 htmlHelper, Expression`1 expression) in D:\Projects\Practice\Mercurial\onlinerestaurant\trunk\ReferenceProjects\aspnetmvc2-rc-sources\src\SystemWebMvc\Mvc\Html\ValidationExtensions.cs:131
ASP.views_admin_createmenucategory_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in d:\Projects\Practice\Mercurial\onlinerestaurant\trunk\OnlineRestaurant\Views\Admin\CreateMenuCategory.ascx:26
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) in D:\Projects\Practice\Mercurial\onlinerestaurant\trunk\ReferenceProjects\aspnetmvc2-rc-sources\src\SystemWebMvc\Mvc\ViewPage.cs:107
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.