Skip to content

ModelBindingResult.Success not accepting null #25275

@Muchiachio

Description

@Muchiachio

Describe the bug

We are testing preview bits on our application and we noticed that ModelBindingResult.Success no longer accepts null values with nullable annotations enabled. Is this intentional or a bug? We don't want to use ModelBindingResult.Failed as we explicitly binding the value to null and don't want other model binders to be used after.

Also didn't want to create new issues so here are other places with potentially incorrect nullability which don't compile now.

  • IModelBinderProvider.GetBinder return should be nullable, example in codebase BinderTypeModelBinderProvider.
  • IUrlHelper.IsLocalUrl(string) parameter should be nullable, for example checking login redirect which can be null, example in codebase UrlHelperBase which checks for null too.

To Reproduce

#nullable enable

public class ModelBinder : IModelBinder
{
    public Task BindModelAsync(ModelBindingContext bindingContext)
    {
        bindingContext.Result = ModelBindingResult.Success(null);

        return Task.CompletedTask;
    }
}

Further technical details

Version:   5.0.100-preview.8.20417.9
Commit:    fc62663a35

Metadata

Metadata

Assignees

Labels

DoneThis issue has been fixedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions