c# - KeyNotFound Exception when calling Html.ValidationSummary() dynamically through helper method -


I have a helpful method in my view that dynamically prepares the whole form. I would like to add a support as available in MVC RC2.

I use the code given below to present the verification summary field on the formation.

  _viewPage.Html.EnableClientValidation (); MvcHtmlString validationSummary = _viewPage.Html.ValidationSummary ("There are errors on this form, please contact your administrator."); If (Validation Ms.! = Null & Verification. Ms. Torstring (!) = "") Response Write (Verification. Summary.ToString ());  

When the code reaches this point, I get an error.

  System.Collections.Generic.KeyNotFoundException User Code  

Message = "The key given was not present in the dictionary." Source = "system" StackTrace: System.ThrowHelper.ThrowKeyNotFoundException (on System.Web.Mvc.Html.ValidationExtensions.ValidationSummary) System.Collections.Generic.SortedDictionary on 2.get_Item (TKey key) (HtmlHelper HtmlHelper, Boolean excludePropertyErrors, string message, IDictionary 2 htmlAttributes) on Fusion.UI.MvcWebUX.Helper.FormGenerator.GenerateFormValidation System.Web.Mvc.Html.ValidationExtensions.ValidationSummary (HtmlHelper HtmlHelper, string message, IDictionary`2 htmlAttributes) (on D) in the \ EBS \ Project.Fusion \ Fusion.UI.MvcWebUX \ Helper \ FormGenerator.cs: \ EBS \ Project.Fusion \ Fusion line Fusion.UI.MvcWebUX.Helper.FormGenerator.GenerateForm () at D. 88 .UI.MvcWebUX \ Helpper \ FormGenerator.cs: \ EBS \ Project.Fusion \ Fusion.UI.MvcWebUX \ h Elpr \ FormGenerator.cs: line Fusion.UI.MvcWebUX.Helper.FormGenerator.RenderForm (ViewPage viewPage) at D 70: ASP.views_shared_autoview_aspx line .__ 60 RenderContent2 (HtmlTextWriter __w, control parameterContainer) d: \ EBS \ Project.Fusion \ Fusion.UI.MvcWebUX \ Views \ shared \ AutoView.aspx: line 7 System.Web.UI.Control.RenderChildrenInternal (HtmlTextWriter writer, ICollection children) .Web.UI.Control.RenderChildren (HtmlTextWriter writer system ) System.Web.UI.Control.Render (HtmlTextWriter writer) on System.Web.UI.Control.RenderControlInternal (HtmlTextWriter writer, ControlAdapter adapter) on System.Web.UI. Control.RenderControl (HtmlTextWriter writer, ControlAdapter adapter) System.Web.UI.Control.RenderControl (HtmlTextWriter writer ASP.views_shared_fusion_master .__ Render__control1) (HtmlTextWriter __w, control parameterContainer) than in d: \ EBS \ Project.Fusion \ Fusion .UI .MvcWebUX \ Views \ shared \ Fusion.Master: line System.Web.UI.Control.RenderChildrenInternal at 74 (HtmlTextWriter writer, ICollection children) System.Web.UI.Control.RenderChildren (HtmlTextWriter writer System.Web.UI ) on .Control.Rend er (HtmlTextWriter writer) System.Web.UI.Control.RenderControlInternal (HtmlTextWriter writer System.Web.UI.Control.RenderControl on System.Web.UI.Control.RenderControl, ControlAdapter adapter) (HtmlTextWriter writer , ControlAdapter Optimizer) (HtmlTextWriter author) System.Web.UI.Co On .Web.Mvc.ViewPage.Render (ntrol.RenderChildren (HtmlTextWriter writer) on System.Web.UI.Control.RenderChildrenInternal (HtmlTextWriter writer, ICollection children) on System.Web.UI.Page.Render (HtmlTextWriter writer on the system) HtmlTextWriter writer) System.Web.UI.Control.RenderControlInternal (HtmlTextWriter writer System.Web.UI.Control.RenderControl on SystemkWeb, ControlAdapter adapter) (HtmlTextWriter writer, ControlAdapter adapter) on .UI.Control.RenderControl (HtmlTextWriter writer ) System.Web.UI.Page.ProcessRequestMain (Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) InnerException:

I h awen been struggling with this for a few hours. Can someone help me solve this and tells me why this is happening.

I have come here for a solution twice, so I will also answer with one thing which This may be due to it.

In MVC 2 RC (I believe, the version given with the 2010 RC), you EnableClientValidation :

  & lt ;% - This is the right way to call these two methods -%> & Lt;% Html Validity beautiful (); & Gt%; & Lt;% Html Enabledclaimitivity (); & Gt%;  

The reason for the exception would be:

  & lt;% - The exception to the side effect of calling ECV before -% & gt; & Lt;% Html Enabledclaimitivity (); & Gt%; & Lt;% Html Validity beautiful (); & Gt%;  

Some such calls are quite dirty to crop side effects from called conandicated method calls. Little reminds me of the global variable.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -