4

代码是不言自明的:

public class TooLateValidator : IApplicationStartupHandler
    {
        public TooLateValidator()
        {
            ContentService.Saving += ContentService_Saving;
        }

        private void ContentService_Saving(IContentService sender, Umbraco.Core.Events.SaveEventArgs<Umbraco.Core.Models.IContent> e)
        {
            if(DateTime.Now.Hour > 21){

                e.Cancel = true;

                //validation message: "it's too late for that"
                // how do I throw this message to UI??

            }
        }
    }

我正在使用 Umbraco 6。

4

2 回答 2

2

根据评论,这是一个模糊的问题,有许多可能的解决方案。很难确切地看到您需要什么,但我会尝试理解。

Umbraco 6 的突出错误之一是对话气泡会显示自定义消息,但它们会立即被 Umbraco 自己的消息覆盖,但您现在可以轻松做到这一点(感谢我的朋友 Ali 提供的代码并在 v6 中为我工作.1.6)。

using System.Web;
using System.Web.UI;
using Umbraco.Core;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.UI;
using Umbraco.Web.UI.Pages;

public class UmbracoEvents : ApplicationEventHandler
{
    protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        //Events
        ContentService.Created += Content_Created;
        ContentService.Saving += Content_Saving;
    }

    private void Content_Saving(IContentService sender, SaveEventArgs<IContent> e)
    {
        // 1 JavaScript 
        HttpContext.Current.Response.Write("<script>alert('Saved!');</script>");                        
        e.Cancel = true;

    }

    private void Content_Created(IContentService sender, NewEventArgs<IContent> e)
    {
        // 2 Umbraco speech bubble

        var clientTool = new ClientTools((Page)HttpContext.Current.CurrentHandler);
        clientTool.ShowSpeechBubble(SpeechBubbleIcon.Success, "Warning", "It is to late to do that!");
    }
}
于 2014-12-21T03:22:28.853 回答
0

尝试这个

 //validation message: "it's too late for that"
 // how do I throw this message to UI??

 e.Messages.Add(new EventMessage("validation message", "it's too late for that", EventMessageType.Error));
于 2017-09-06T01:42:58.920 回答