//ActionResult not IActionResult //public override void ExecuteResult(ActionContext context) //{ // PrepareMessage(context); // InnerResult.ExecuteResult(context); //} private void PrepareMessage(ActionContext context) { var tempData = context.HttpContext.RequestServices.GetRequiredService<ITempDataDictionary>(); var alert = new Alert(AlertClass, Message); if (AppendToExistingMessages) tempData.AddAlert(alert); else tempData.SetAlert(alert); }
public static void AddAlert(this ITempDataDictionary tempData, Alert alert) { if (!tempData.ContainsKey(Alerts)) { tempData.Set(Alerts, new List<Alert>()); } var alerts = tempData.Get<List<Alert>>(Alerts); alerts.Add(alert); tempData.Set(Alerts, alerts); }
public static void SetAlert(this ITempDataDictionary tempData, Alert alert) { if(tempData != null && alert != null) tempData.Set(Alerts, new List<Alert> { alert }); }