2015-04-07 31 views
2

在一把umbraco V7如何顯示上的後臺自定義錯誤的驗證信息保存或發佈到用戶一把umbraco的後臺保存驗證

我曾嘗試以下,但它顯示沒有實際的錯誤「出版工作由第三方插件取消」消息

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

這似乎是一個[已知問題](http://issues.umbraco.org/issue/U4-5927),並且修復將在7.3.0中發佈。如果您之前需要某些東西,則可以使用[此處]描述的解決方法(https://our.umbraco.org/forum/umbraco-7/developing-umbraco-7-packages/53699-User-Message-%28former-Speech -bubble%29中,自定義事件)。 –

回答

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 
    } 

}