1

我已经看到了几个如何在编辑内容时将验证消息发送回 UI 的示例,就像这样。

public class StandardPageValidator : IValidate<standardpage>
{
    IEnumerable<validationerror> IValidate<standardpage>.Validate(StandardPage instance)
    {
        // Silly example to validate if the PageName and MainBody properties start with the same letter
        if (instance.PageName.StartsWith(EPiServer.Core.Html.TextIndexer.StripHtml(instance.MainBody.ToHtmlString().Substring(0, 1), int.MaxValue)))
        {
            return new[] { new ValidationError() { 
                ErrorMessage = "Main body and PageName cannot start with the same letter", 
                PropertyName = "PageName", RelatedProperties = new string[] { "MainBody" }, 
                Severity = ValidationErrorSeverity.Error, 
                ValidationType = ValidationErrorType.AttributeMatched
            } };
        }

        return new ValidationError[0];
    }
}

但是,我想在拦截 Published Content Event 后向 UI 发送一条消息,但是这个方法返回 void 那么我该怎么做呢?

    public void Initialize(InitializationEngine context)
    {
        var events = ServiceLocator.Current.GetInstance<IContentEvents>();
        events.PublishedContent += EventsPublishedContent;
    }
    private void EventsPublishedContent(object sender, ContentEventArgs e)
    {
    if (e.Content is myType)
    {
        //do some business logic work....


       //How can I send a Info Message back to the UI here?
    }
}
4

1 回答 1

1

您可以EventsPublishedContent在代码示例中执行此操作:

e.CancelAction = true;
e.CancelReason = "This message will be displayed in the UI.";
于 2018-04-17T07:40:14.353 回答