Last active
May 30, 2023 15:43
-
-
Save AndyButland/4e39ad907b0e4bf13c1e1d6907c5b1ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FormEntryDtoModelBinder : IModelBinder | |
{ | |
public async Task BindModelAsync(ModelBindingContext bindingContext) | |
{ | |
if (bindingContext == null) | |
{ | |
throw new ArgumentNullException(nameof(bindingContext)); | |
} | |
using (var reader = new StreamReader(bindingContext.HttpContext.Request.Body)) | |
{ | |
var body = await reader.ReadToEndAsync().ConfigureAwait(continueOnCapturedContext: false); | |
FormEntryDto? value = JsonSerializer.Deserialize<FormEntryDto>(body); | |
if (value != null) | |
{ | |
bindingContext.Result = ModelBindingResult.Success(value); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment