mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#2540: Fixes an issue with NotifyFilter.
This fixes the case when a controller for example registers a notification and then returns a View result instead of a Redirect result. When returning a View, the registered notifications would not be rendered until another page request occurred. Fixes #2540
This commit is contained in:
@@ -61,28 +61,40 @@ namespace Orchard.UI.Notify {
|
|||||||
|
|
||||||
public void OnActionExecuted(ActionExecutedContext filterContext) {
|
public void OnActionExecuted(ActionExecutedContext filterContext) {
|
||||||
|
|
||||||
// don't touch temp data if there's no work to perform
|
// Don't touch temp data if there's no work to perform.
|
||||||
if (!_notifier.List().Any())
|
if (!_notifier.List().Any())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var messageEntries = _notifier.List().ToList();
|
||||||
|
|
||||||
|
if (filterContext.Result is ViewResultBase) {
|
||||||
|
// Assign values to the Items collection instead of TempData and
|
||||||
|
// combine any existing entries added by the previous request with new ones.
|
||||||
|
var existingEntries = filterContext.HttpContext.Items[TempDataMessages] as IList<NotifyEntry> ?? new List<NotifyEntry>();
|
||||||
|
messageEntries = messageEntries.Concat(existingEntries).ToList();
|
||||||
|
filterContext.HttpContext.Items[TempDataMessages] = messageEntries;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var tempData = filterContext.Controller.TempData;
|
var tempData = filterContext.Controller.TempData;
|
||||||
|
|
||||||
// initialize writer with current data
|
// Initialize writer with current data.
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
if (tempData.ContainsKey(TempDataMessages)) {
|
if (tempData.ContainsKey(TempDataMessages)) {
|
||||||
sb.Append(tempData[TempDataMessages]);
|
sb.Append(tempData[TempDataMessages]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// accumulate messages, one line per message
|
// Accumulate messages, one line per message.
|
||||||
foreach (var entry in _notifier.List()) {
|
foreach (var entry in messageEntries) {
|
||||||
sb.Append(Convert.ToString(entry.Type))
|
sb.Append(Convert.ToString(entry.Type))
|
||||||
.Append(':')
|
.Append(':')
|
||||||
.AppendLine(entry.Message.ToString())
|
.AppendLine(entry.Message.ToString())
|
||||||
.AppendLine("-");
|
.AppendLine("-");
|
||||||
}
|
}
|
||||||
|
|
||||||
// assign values into temp data
|
// Result is not a view, so assume a redirect and assign values to TemData.
|
||||||
// string data type used instead of complex array to be session-friendly
|
// String data type used instead of complex array to be session-friendly.
|
||||||
tempData[TempDataMessages] = sb.ToString();
|
tempData[TempDataMessages] = sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user