Using a model binder it is possible to pass a NULL complex type to a controller endpoint.
This solution does not work for all controller endpoints, rebuilding the model is also not straight forward.
Is there a better solution to pass a NULL complex type parameter in ASP.NET Core?
This functionality works as expected (allows NULLs) using .NET Standard without any modifications.
Using the following IModelBinder and IModelBinderProvider:
public class NullModelBinderProvider : IModelBinderProvider
{
public IModelBinder GetBinder(ModelBinderProviderContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if (context.Metadata.ModelType == typeof(BreakSize))
{
return new BinderTypeModelBinder(typeof(NullModelBinder));
}
return null;
}
}
public class NullModelBinder : IModelBinder
{
public Task BindModelAsync(ModelBindingContext bindingContext)
{
if (bindingContext == null)
throw new ArgumentNullException("bindingContext");
// If null than pass null to the controller - this works
if (bindingContext.HttpContext.Request.Form.ContainsKey(bindingContext.FieldName) && string.IsNullOrEmpty(bindingContext.HttpContext.Request.Form[bindingContext.FieldName]))
bindingContext.Result = ModelBindingResult.Success(null);
else
bindingContext.Result = ModelBindingResult.Success(new BreakSize()); // Todo set values for BreakSize from the form
return Task.CompletedTask;
}
}

Assuming your controller action looks like this:
ASP.NET Core by default performs validation, i.e. it will check for nulls and throw 400. If you want to allow nulls, you need to use mark it as nullable:
or