Skip to content

Commit

Permalink
Fixed issue with model state marked as invalid on the entire model, w…
Browse files Browse the repository at this point in the history
…here we handle it for each item separately
  • Loading branch information
bergmania committed Aug 11, 2021
1 parent dfa76af commit c5e8826
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -913,9 +913,9 @@ private async Task<ActionResult<ContentItemDisplay>> PostSaveInternal(ContentIte
v.Notifications.AddRange(n.Notifications);
}

//lastly, if it is not valid, add the model state to the outgoing object and throw a 400
HandleInvalidModelState(display, cultureForInvariantErrors);

//lastly, if it is not valid, add the model state to the outgoing object and throw a 400
if (!ModelState.IsValid)
{
return ValidationProblem(display, ModelState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ private async Task OnActionExecutingAsync(ActionExecutingContext context)
var model = (ContentItemSave) context.ActionArguments["contentItem"];
var contentItemValidator = new ContentSaveModelValidator(_loggerFactory.CreateLogger<ContentSaveModelValidator>(), _propertyValidationService);

if (context.ModelState.ContainsKey("contentItem"))
{
// if the entire model is marked as error, remove it, we handle everything separately
context.ModelState.Remove("contentItem");
}

if (!ValidateAtLeastOneVariantIsBeingSaved(model, context)) return;
if (!contentItemValidator.ValidateExistingContent(model, context)) return;
if (!await ValidateUserAccessAsync(model, context)) return;
Expand Down

0 comments on commit c5e8826

Please sign in to comment.