We just recently upgraded our application and noticed that we’re getting runtime errors on all of our Html.ValidationMessages and Html.ValidationMessageFor. There error is: The given key was not present in the dictionary. We’ve been passing the modelName/expression and it was working fine until the upgrade. I also checked out the breaking changes as described in the readme but didn’t notice anything that relates to it.
We just recently upgraded our application and noticed that we’re getting runtime errors on
Share
After having debugged the ASP.NET MVC source I found the cause for this issue.
You have to have <%= Html.EnableClientSideValidation %> before the <% Html.BeginForm %> ,
The reason for this is that when client side validation is enabled the Html form helper will generate an Id (formContext.FormId) that is used in the validation helper. This means that if you are to use the validation helper you must use the built in form helpers.
So to solve the issue just move the <%= Html.EnableClientSideValidation %> to above the first form and be sure to use the Html.BeginForm helper method.