Last active
May 30, 2023 15:43
-
-
Save AndyButland/fd5c7ec8b07d44c7b09d4b65abd65858 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 = JsonConvert.DeserializeObject<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