0

I have a form, which allows the user to change dependencies between two kinds of objects.

I have one set that has 30 elements, and for every one of those 30 elements I can choose one, several, or all of the 26 elements of the other collection. So it basically means that I have something like 30*26 checkboxes(complex but complex due to the business logic). And I may have this several times on the same page, so I think I may have something like 1100+ elements.

It's basically stored in this model:

public class VarDependency{
   public int Id { get; set; }
   public String Name { get; set; }
   public List<ValueDependency> Values { get; set; }
}

public class ValueDependency{
   public int Id { get; set; }
   public String Name{ get; set; }
   public List<AvailableValue> Triggers { get; set; }
}

public class AvailableValue{
   public bool IsSelected { get; set; }
   public String Text { get; set; }
   public int Value { get; set; }
}

In the view, I basically have two loops. For every available Value, I have a LabelFor (based on the Text property), a checkbox (based on the IsSelected), and a hidden field (based on the Value).

When I do not have so many elements (something like 15*15), everything is working fine. I receive the data in my controller and I can handle them, but I don't know exactly why, if I get more elements, I get an exception quickly, before it even gets to the controller:

System.InvalidOperationException Operation is not valid due to the current state of the object.

System.Web.HttpException (0x80004005): The URL-encoded form data is not valid. ---> System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded()
   at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding)
   at System.Web.HttpRequest.FillInFormCollection()
   at System.Web.HttpRequest.FillInFormCollection()
   at System.Web.HttpRequest.get_Form()
   at Microsoft.Web.Infrastructure.DynamicValidationHelper.ValidationUtility.CollectionReplacer.<>c__DisplayClass8.<MakeCollectionsLazy>b__2()
   at Microsoft.Web.Infrastructure.DynamicValidationHelper.ValidationUtility.CollectionReplacer.<>c__DisplayClass12.<ReplaceCollection>b__e()
   at Microsoft.Web.Infrastructure.DynamicValidationHelper.ValidationUtility.CollectionReplacer.<>c__DisplayClass12.<ReplaceCollection>b__11()
   at Microsoft.Web.Infrastructure.DynamicValidationHelper.DeferredCountArrayList.get_Count()
   at System.Collections.Specialized.NameObjectCollectionBase.get_Count()
   at System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc, RequestValidationSource requestCollection)
   at System.Web.HttpRequest.get_Form()
   at System.Web.HttpRequestWrapper.get_Form()
   at System.Web.Mvc.HttpRequestExtensions.GetHttpMethodOverride(HttpRequestBase request)
   at System.Web.Mvc.AcceptVerbsAttribute.IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
   at System.Web.Mvc.HttpPostAttribute.IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
   at System.Web.Mvc.ActionMethodSelector.<>c__DisplayClass11.<RunSelectionFilters>b__d(ActionMethodSelectorAttribute attr)
   at System.Linq.Enumerable.All[TSource](IEnumerable`1 source, Func`2 predicate)
   at System.Web.Mvc.ActionMethodSelector.RunSelectionFilters(ControllerContext controllerContext, List`1 methodInfos)
   at System.Web.Mvc.ActionMethodSelector.FindActionMethod(ControllerContext controllerContext, String actionName)
   at System.Web.Mvc.ReflectedControllerDescriptor.FindAction(ControllerContext controllerContext, String actionName)
   at System.Web.Mvc.ControllerActionInvoker.FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, String actionName)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
   at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
   at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Even in debug mode in Visual Studio, I don't get thrown an exception.

I can't find any lead about how to resolve this problem, so any help would be very appreciated, the problem appear when we are doing some tests on the release :/

MaxDataSol
  • 358
  • 1
  • 2
  • 18
J4N
  • 19,480
  • 39
  • 187
  • 340

1 Answers1

3

I think this may be due to the recently introduced default maximum number of controls that a page can have. You can change this in web.config Have a look at this question:

ASP.NET MS11-100: how can I change the limit on the maximum number of posted form values?

Community
  • 1
  • 1
andyb
  • 770
  • 5
  • 11
  • Yes thank you, I found the same link 30min ago. Do you know if there is other setting of this kind? Because I've another similar problem, and my model is null, but for now, I only managed to reproduce it on an IIS Server – J4N Sep 06 '12 at 13:08