Niharika Vachhani

Niharika Vachhani

  • NA
  • 34
  • 4.2k

Toastr in mvc 5 not working

Aug 23 2018 3:52 AM

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.

i pass message from controller like this
 this.AddToastMessage("", "Menu Added Successfully", ToastType.Success);
 
 
 
this is my toast message class
 
[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; } }
 this is my toastr class
 
[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; } }
please can any one help me to solve the problem ..what i am doing wrong.? 

Answers (1)