MvcOptions.MaxModelBindingCollectionSize Property

Definition

Gets or sets the maximum size of a complex collection to model bind. When this limit is reached, the model binding system will throw an InvalidOperationException.

C#
public int MaxModelBindingCollectionSize { get; set; }

Property Value

The default value is 1024, matching DefaultValueCountLimit.

Remarks

When binding a collection, some element binders may succeed unconditionally and model binding may run out of memory. This limit constrains such unbounded collection growth; it is a safeguard against incorrect model binders and models.

This limit does not correct the bound model. The InvalidOperationException instead informs the developer of an issue in their model or model binder. The developer must correct that issue.

This limit does not apply to collections of simple types. When CollectionModelBinder<TElement> relies entirely on IValueProviders, it cannot create collections larger than the available data.

A very high value for this option (int.MaxValue for example) effectively removes the limit and is not recommended.

Applies to

Product Versions
ASP.NET Core 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0