Use Toastr messages from codebehind

1 comment
I have been using the excellent toastr library for my clientside messages now for a while.

Today I needed to send a message from codebehind to the client and I wanted to keep using toastr.

As I prefer to solve things only once I wanted this to be reusable through my app.
Something like:

var msg= new Message(Level.Error,"This is the text", "This is the title"));
viewmodel.Messages.Add(msg);

and then have this show up the nice toastr way:





(See demo over at GitHub for all the options.)


So to have a reusable way to send messages to my users with Toastr I came up with this model:


First I define a model for messages


Next I create a ViewModel class and inherit from it:



In the controller I can now easily add messages:




Add finally make them pop up in the view:






I can now add multiple messages with different levels, all from codebehind:



1 comment :

  1. The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface. recover deleted iMessages

    ReplyDelete