1414using Microsoft . AspNetCore . Http ;
1515using Microsoft . AspNetCore . Mvc ;
1616using Microsoft . AspNetCore . Mvc . Filters ;
17+ using Microsoft . AspNetCore . Mvc . ModelBinding . Binders ;
18+ using Microsoft . AspNetCore . Mvc . ModelBinding ;
19+ using System . Threading . Tasks ;
1720
1821
1922namespace GeneXus . Utils
@@ -29,6 +32,36 @@ public void OnActionExecuting(ActionExecutingContext context)
2932 ( context . Controller as GxRestService ) . Initialize ( ) ;
3033 }
3134 }
35+
36+ public class QueryStringModelBinderProvider : IModelBinderProvider
37+ {
38+ public IModelBinder GetBinder ( ModelBinderProviderContext context )
39+ {
40+ if ( context . BindingInfo . BindingSource == BindingSource . Query &&
41+ context . Metadata . ModelType == typeof ( string ) )
42+ {
43+ return new BinderTypeModelBinder ( typeof ( CustomQueryStringBinder ) ) ;
44+ }
45+ return null ;
46+ }
47+ }
48+ public class CustomQueryStringBinder : IModelBinder
49+ {
50+ public Task BindModelAsync ( ModelBindingContext bindingContext )
51+ {
52+ if ( ! bindingContext . BindingSource . CanAcceptDataFrom ( BindingSource . Query ) )
53+ {
54+ return Task . CompletedTask ;
55+ }
56+ if ( bindingContext . ModelType != typeof ( string ) )
57+ {
58+ return Task . CompletedTask ;
59+ }
60+ string value = bindingContext . ValueProvider . GetValue ( bindingContext . ModelName ) . FirstValue ;
61+ bindingContext . Result = ModelBindingResult . Success ( value ?? string . Empty ) ;
62+ return Task . CompletedTask ;
63+ }
64+ }
3265 [ TypeFilter ( typeof ( CustomActionFilter ) ) ]
3366 public class GxRestService : ControllerBase
3467 {
0 commit comments