Share via


MvcOptions.MaxModelBindingRecursionDepth Property

Definition

Gets or sets the maximum recursion depth of the model binding system. The DefaultModelBindingContext will throw an InvalidOperationException if more than this number of IModelBinders are on the stack. That is, an attempt to recurse beyond this level will fail.

public:
 property int MaxModelBindingRecursionDepth { int get(); void set(int value); };
public int MaxModelBindingRecursionDepth { get; set; }
member this.MaxModelBindingRecursionDepth : int with get, set
Public Property MaxModelBindingRecursionDepth As Integer

Property Value

The default value is 32, matching the default MaxValidationDepth value.

Remarks

For some self-referential models, some binders may succeed unconditionally and model binding may result in stack overflow. This limit constrains such unbounded recursion; it is a safeguard against incorrect model binders and models. This limit also protects against very deep model type hierarchies lacking self-references.

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

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

Applies to