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; Â Â Â Â Â Â Â Â } Â Â Â Â Â Â ...