From c5e882680b977dfa3a85f094780ce1b8dd049977 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 11 Aug 2021 15:43:41 +0200 Subject: [PATCH] Fixed issue with model state marked as invalid on the entire model, where we handle it for each item separately --- src/Umbraco.Web.BackOffice/Controllers/ContentController.cs | 2 +- .../Filters/ContentSaveValidationAttribute.cs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs index 6cb0addb719a..183284d5b854 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs @@ -913,9 +913,9 @@ private async Task> 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); diff --git a/src/Umbraco.Web.BackOffice/Filters/ContentSaveValidationAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/ContentSaveValidationAttribute.cs index d4aafe83ff40..4b8fb6acb378 100644 --- a/src/Umbraco.Web.BackOffice/Filters/ContentSaveValidationAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/ContentSaveValidationAttribute.cs @@ -68,6 +68,12 @@ private async Task OnActionExecutingAsync(ActionExecutingContext context) var model = (ContentItemSave) context.ActionArguments["contentItem"]; var contentItemValidator = new ContentSaveModelValidator(_loggerFactory.CreateLogger(), _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;