Skip to content

Commit

Permalink
Add AddModelError.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahelsaig committed Aug 9, 2024
1 parent af9a45f commit ce2be53
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#nullable enable

using Microsoft.Extensions.Localization;
using OrchardCore.DisplayManagement.Entities;
using OrchardCore.DisplayManagement.ModelBinding;
using System;
using System.Threading.Tasks;

Expand Down Expand Up @@ -71,4 +73,11 @@ public static async Task<TViewModel> CreateModelAsync<TViewModel>(this BuildEdit
await context.Updater.TryUpdateModelAsync(viewModel, prefix);
return viewModel;
}

/// <summary>
/// Adds an error message to the <see cref="BuildShapeContext.Updater"/>.<see cref="IUpdateModel.ModelState"/>. The
/// <paramref name="message"/> is <see cref="LocalizedString"/>, because it's user-facing data.
/// </summary>
public static void AddModelError(this BuildEditorContext context, string key, LocalizedString message) =>
context.Updater.ModelState.AddModelError(key, message);
}

0 comments on commit ce2be53

Please sign in to comment.