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. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru Dot Net Training in Chennai. Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

    ReplyDelete