Table of Contents

DisableModelBindingAttribute Class

Definition

Provides a generic way to disable IValueProviderFactory implementations used for model binding.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple = true)]
public class DisableModelBindingAttribute : Attribute, IAsyncResourceFilter, IFilterMetadata
Inheritance
DisableModelBindingAttribute
Implements
Inherited Members

Examples

The following example demonstrates how to use the to disable a specific model binding value provider, such as when handling file uploads to prevent form value binding.

using System;
using Cuemon.AspNetCore.Mvc.Filters.ModelBinding;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;

namespace MyApp.Examples;

[DisableModelBinding(typeof(FormValueProviderFactory))]
public class FileUploadController : Controller
{
    [HttpPost("/upload")]
    public IActionResult Upload()
    {
        return Ok("File upload processed.");
    }
}

public class DisableModelBindingAttributeDirectUsage
{
    public void Demonstrate()
    {
        // Direct instantiation of DisableModelBindingAttribute
        var attribute = new DisableModelBindingAttribute(typeof(FormValueProviderFactory));
        Console.WriteLine($"Disabled type: {attribute.ValueProviderFactoryType.Name}");
    }
}

Remarks

Constructors

Name Description
DisableModelBindingAttribute(Type)

Initializes a new instance of the DisableModelBindingAttribute class.

Properties

Name Description
ValueProviderFactoryType

Gets the type that needs to be disabled on class or method level.

Methods

Name Description
OnResourceExecutionAsync(ResourceExecutingContext, ResourceExecutionDelegate)

Called asynchronously before the rest of the pipeline.

See Also