Umbraco后台保存验证

时间:2015-04-07 10:51:30

标签: c# umbraco

在Umbraco V7中,如何在后台保存或发布给用户

上显示自定义错误验证消息

我已尝试过关注,但它显示'发布已被第三方插件取消'而非实际错误消息

void ContentService_Saving(IContentService sender, SaveEventArgs<IContent> e)
{               
     e.Cancel = true;       
     ShowErrorBubble("Error saving item", "Error:duplicate records exists");
}

private static void ShowErrorBubble(string title, string exception)
{           
    try
    {
        umbraco.BasePages.UmbracoEnsuredPage.Current.ClientTools.ShowSpeechBubble(umbraco.BasePages.UmbracoEnsuredPage.speechBubbleIcon.error, title, exception);

    }

    catch (Exception ex)
    {
            //do nothing at the moment, forums suggest we cannot send an error message
    }

}

1 个答案:

答案 0 :(得分:1)

这是您正在使用的旧代码段。无论如何,它从来没有正常工作过。请尝试使用此代码:

void ContentService_Saving(IContentService sender, SaveEventArgs e)
{                      
     ShowErrorBubble(e, "Error saving item", "Error:duplicate records exists");

}

private static void ShowErrorBubble(SaveEventArgs e, string title, string text)
{           
    try
    {
        e.Messages.Add(new Umbraco.Core.Events.EventMessage(title, text, Umbraco.Core.Events.EventMessageType.Warning));

        e.Cancel = true;
    }

    catch (Exception ex)
    {
            //do nothing at the moment, forums suggest we cannot send an error message
    }

}