services. AddMvc (options=& gt;
{
//need to insert into the first article, built-in default is matched to the appropriate Provider will not continue to bind down; If you add to the end, that is, don't call to our implementation
Options. ModelBinderProviders. Insert (0, new StringTrimModelBinderProvider (options. InputFormatters));
});
But in this way, the custom setting global bindings, and I just want to in the specified model is valid in the argument, but don't know how to pass in the options. InputFormatters, I write this, but cannot identify, please tall person to give directions, thank!
[ModelBinder (BinderType=typeof (StringTrimModelBinderProvider (options. InputFormatters))))
Public class TestModel
{
//...
}
Complement, this StringTrimModelBinderProvider classes, in his the constructor is need to
Public StringTrimModelBinderProvider (IList
{
_formatters=formatters;
}
CodePudding user response:
[ModelBinder (BinderType=typeof (StringTrimModelBinderProvider)]He is the type, not construct,
System for lookup type, not construct, he is actually a ModelBindeService. Internal AddSingle (typeof (XXXX), XXXX)
So you only need to modify the scarlet letter part can
The remaining part, two methods
Method one: don't need to entanglements that structure, removed, directly on the IModelBinderProvider
Interface methods to write directly in the var mvcoptions=context. Services. GetService
Public IModelBinder GetBinder (ModelBinderProviderContext context)
{
Var mvcoptions=context. Services. GetService
}
Method 2:
If you really have to struggle the place, be sure to write according to your idea, then we can be written as
Service. AddSingler
The class StringTrimModelBinderProvider
{
StringTrimModelBinderProvider (IOptions
{
}
}
Services. AddMvc (options=& gt;
{
Services. AddSingleton
Services. AddControllers (.) AddMvcOptions (options=& gt; Options. ModelBinderProviders. Insert (0, services. BuildServiceProvider () GetService
});
Ps: all this hosting part of the operation, or they don't want to listen to those people don't want to see, want to play what netcore, first thing please learn hosting part, not the jump about EF, Razor, datatable, abp, Microsoft back, at this, the whole netcore is blind, how would you like to clear this, netcore play will do
CodePudding user response: