DisableModelBindingAttribute Class
Definition
- Namespace
- Cuemon.AspNetCore.Mvc.Filters.ModelBinding
- Assemblies
- Cuemon.AspNetCore.Mvc.dll
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
This attribute was inspired by this source on GitHub: https://github.com/aspnet/Entropy/blob/rel/1.1.1/samples/Mvc.FileUpload/Filters/DisableFormValueModelBindingAttribute.cs.
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. |