when i pass message from controller the message will pass to view but when i declare it as toastr it returns null value.i want to pass message to my helper class. but its not working.
this.AddToastMessage("", "Menu Added Successfully", ToastType.Success);
[Serializable] public class ToastMessage { public string Title { get; set; } public string Message { get; set; } public ToastType ToastType { get; set; } public bool IsSticky { get; set; } } [Serializable] public class Toastr { public bool ShowNewestOnTop { get; set; } public bool ShowCloseButton { get; set; } public List<ToastMessage> ToastMessages { get; set; } public ToastMessage AddToastMessage(string title, string message, ToastType toastType) { var toast = new ToastMessage() { Title = title, Message = message, ToastType = toastType }; ToastMessages.Add(toast); return toast; } public Toastr() { ToastMessages = new List<ToastMessage>(); ShowNewestOnTop = false; ShowCloseButton = false; } } public static class ControllerExtensions { public static ToastMessage AddToastMessage(this Controller controller, string title, string message, ToastType toastType = ToastType.Info) { Toastr toastr = controller.TempData["Toastr"] as Toastr; toastr = toastr ?? new Toastr(); var toastMessage = toastr.AddToastMessage(title, message, toastType); controller.TempData["Toastr"] = toastr; return toastMessage; } }
[Serializable] public class Toastr { public bool ShowNewestOnTop { get; set; } public bool ShowCloseButton { get; set; } public List<ToastMessage> ToastMessages { get; set; } public ToastMessage AddToastMessage(string title, string message, ToastType toastType) { var toast = new ToastMessage() { Title = title, Message = message, ToastType = toastType }; ToastMessages.Add(toast); return toast; } public Toastr() { ToastMessages = new List<ToastMessage>(); ShowNewestOnTop = false; ShowCloseButton = false; } }