Creating PersonsCsvBinder
Let's build a binder.
To create ModelBinder
, add a new class called PersonsCsvBinder
, which implements IModelBinder
. In the BindModelAsync
method, we get ModelBindingContext
with all the information in it that we need in order to get the data and to deserialize it. The following code snippets show a generic binder that should work with any list of models. We have split it into sections so that you can clearly see how each part of the binder works:
public class PersonsCsvBinder : IModelBinder { public async Task BindModelAsync( ModelBindingContext bindingContext) { if (bindingContext == null) { return; } ...