How do we prevent the Notifier from rendering duplicate alerts / messages?

Topics: General
May 13, 2013 at 10:00 PM
Hi there,

The notifier is rendering a duplicate information message, because we are rendering a ViewResult and a child PartialViewResult. OnResultExecuting executes for the ViewResult and the PartialViewResult, which means that Orchard.UI.Notify.NotifyFilter.OnResultExecuting fires twice, which means it adds the message twice. For now we have just stopped using a partial view. Is there another way to prevent duplicate message?

The Duplicate Message
Image

The Code Called Twice in Orchard.UI.Notify.NotifyFilter.OnResultExecuting
 messagesZone = messagesZone.Add(_shapeFactory.Message(messageEntry));
Thanks for reading.

Cheers.
Shaun
May 14, 2013 at 8:05 AM
Edited May 14, 2013 at 8:05 AM
yep, i had the same issue as well.
You need to go into the notifyfilter.cs and add these 2 lines at top.
in order to ignore the processing coming from the partial view execution.
  public void OnActionExecuted(ActionExecutedContext filterContext) {
  
            //if is child action do not apply message box (only invoke on explict requests ) not child requests such as ( @Html.Action("GetView", "Constant")) in the view
            if (filterContext.Controller.ControllerContext.IsChildAction == true) return;

}
 public void OnResultExecuting(ResultExecutingContext filterContext) {
   //if is child action do not apply message box (only invoke on explict requests ) not child requests such as ( @Html.Action("GetView", "Constant")) in the view
 if (filterContext.Controller.ControllerContext.IsChildAction == true) return;
}
yiannis.
May 14, 2013 at 4:56 PM
Hi Yiannis,

Thank you for the code. It's a good idea, although I am hesitant to use it, because it modifies the Orchard.Framework project code, which I understand is frowned upon. I am wondering if there is a way to get the same behavior though a module.

Cheers.
Shaun
May 14, 2013 at 5:00 PM
sure , just copy code from core and create your own notifier in your module , and use that.
although i think this should be issued as a potential fix in the core , as i think many will want this behaviour too.
yiannis.
May 14, 2013 at 5:36 PM
I'll give that a try. Thanks.
Oct 14, 2013 at 2:11 PM
Edited Oct 14, 2013 at 2:11 PM
To get rid of duplicates you may not need to alter or copy notifyfilter.cs.

I just simply copied the Messages.cshtml and placed the copy in my Theme's ~/Views folder. I then modified my copy of Messages.cshtml for my own purposes to display thusly:
@using (Script.Foot())
{
    <script type="text/javascript">
        $(document).ready(function () {
            $(".alert").alert();
        });
    </script>
}

<div class="@Model.Type @((Model.Type).ToString() == 
     "Error" ? "infobox-red" : (Model.Type).ToString() == 
     "Information" ? "infobox-green" : "") ">
   @* <a class="close" data-dismiss="alert" href="#">×</a>*@
    <span class="infobox-msg">
        <strong>@Html.Raw(Html.Encode(Model.Message).Replace("\n", "<br />"))</strong>
    </span>
</div>
This took care of the duplicate rendering of alerts for me. HTH someone.