Facebook Notification App Using SignalR, jQuery, And EF 6.0 In ASP.NET MVC

Introduction

SignalR is a library for ASP.NET developers that simplifies the process of adding real-time web functionality to applications. Real-time web functionality is the ability to make server code push the content to connected clients instantly as it becomes available, rather than having the server wait for a client to request the new data.

To Know more about SignalR, you can visit my blogs and articles.

 
Description

SignalR can be used to add any sort of "real-time" web functionality to your MVC application. While Chat is often used as an example, you can do a whole lot more; examples include dashboards and monitoring applications, collaborative applications such as simultaneous editing of documents, job progress updates, and real-time forms. We must have a way to notify all the connected clients if there are any changes on the server, without a refresh or update the web page. This is the scenario in which ASP.NET SignalR comes handy.

Here, I have created two Views -  for home and for Notification entry details. After that, the notifiation message will come with counting the no. of notifications arrived.
 
Link to download my project
 
 
Steps to be followed

Step 1

Create one MVC application named "SignalRDemo".

Step 2


Create a table named "tblEmployee". Paste the following code in that.
  1. SET ANSI_NULLS ON  
  2. GO  
  3.   
  4. SET QUOTED_IDENTIFIER ON  
  5. GO  
  6.   
  7. SET ANSI_PADDING ON  
  8. GO  
  9.   
  10. CREATE TABLE [dbo].[tblEmployee](  
  11.     [ID] [int] IDENTITY(1,1) NOT NULL,  
  12.     [Name] [varchar](50) NULL,  
  13.     [AddedOn] [datetime] NULL,  
  14. PRIMARY KEY CLUSTERED   
  15. (  
  16.     [ID] ASC  
  17. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,   
  18.   
  19. ALLOW_PAGE_LOCKS = ONON [PRIMARY]  
  20. ON [PRIMARY]  
  21.   
  22. GO  
  23.   
  24. SET ANSI_PADDING OFF  
  25. GO 
Step 3

Enable Service Broker on the database. 
  1. ALTER DATABASE Your_DB_Name SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE ; 
Enable Service Broker on the database

Service Broker is a feature introduced for the first time in SQL Server 2005. By using this feature, external or internal processes can send and receive asynchronous messages reliably by using extensions of Transact-SQL Data Manipulation Language (DML). It is a queued and reliable messaging mechanism used for asynchronous programming model.We need this feature to be enabled since, whenever a change in the table will happen such as Insert/Update/Delete/Truncate, then the SQLDependency should be able to identify that.
 
It (Service Broker) rather implements a Broker Architecture which publishes the events while the SQL Dependency acts as a subscriber and detects the changes. Using the SqlDependency object, the application can create and register to receive notifications via the OnChangeEventHandler event handler.

How To Check Service Broker on the database Is Enabled Or Not? 
  1. SELECT NAME, IS_BROKER_ENABLED FROM SYS.DATABASES  
  2. WHERE NAME='Your_db_name' 
Here I ennabled so IS_BROKER_ENABLED column shows "1" , else will show "0".

 
 
Step4

Add Ado.Net Entity Data Model named "SignalRDataModel.edmx".

Go to Solution Explorer (Visual studio) > Right Click on Project name form Solution Explorer > Add > New item > Select ADO.net Entity Data Model under data > Enter model name > Add.

A popup window will come (Entity Data Model Wizard) > Select Generate from database > Next > Chose your data connection > select your database > next > Select tables > enter Model Namespace > Finish.

Step5

Install SignalR NuGet Package.


Solution Explorer > Right Click on References > Manage NuGetPackages > Search for "SignalR"> Install > Close.

Or you can also install from package manager console.


Go to Tools (top menu) > Library Package Manager > Open "Package Manager Console" and Type below command .
  1. PM> Install-Package Microsoft.AspNet.SignalR 
 
Step6

Add an Owin startup file.

Add an Owin startup class in your application for enabling the SignalR in our application. Add a new class in the project named "Startup.cs"

Code Ref
  1. using Microsoft.Owin;  
  2. using Owin;  
  3. using System;  
  4. using System.Collections.Generic;  
  5. using System.Linq;  
  6. using System.Web;  
  7.   
  8. [assembly: OwinStartup(typeof(SignalRDemo.Startup))]  
  9.   
  10. namespace SignalRDemo  
  11. {  
  12.     public class Startup  
  13.     {  
  14.         public void Configuration(IAppBuilder app)  
  15.         {  
  16.             app.MapSignalR();  
  17.         }  
  18.     }  

Step7

Add a SignalR hub class.

Now, you need to create a SignalR Hub class, this makes possible to invoke the client side JavaScript method from the server side. In this application, we will use this for showing notification.SignalR uses ‘Hub’ objects to communicate between the client and the server.
Add a new class named "NotificationHub.cs".

Code Ref
  1. using Microsoft.AspNet.SignalR;  
  2. using System;  
  3. using System.Collections.Generic;  
  4. using System.Linq;  
  5. using System.Web;  
  6.   
  7. namespace SignalRDemo  
  8. {  
  9.     public class NotificationHub : Hub  
  10.     {  
  11.         //Nothing required here   
  12.         //public void Hello()  
  13.         //{  
  14.         //    Clients.All.hello();  
  15.         //}  
  16.     }  

The NotificationHub.cs class is empty. I will use the class later from another place.
 
Step8

Add connection string into the web.config file.

Open the application root Web.config file and find the element. Add the following connection string to the element in the Web.config file.

Code Ref
  1. <add name="sqlConString" connectionString="Your_Connection_String" /> 
Step9

Add another class file named "NotificationComponent.cs" for register notification for data changes in the database In this class, you need to create a SQL dependency which allows your application to be notified when a data has changed in the database (Microsoft SQL Server).

Write the following in this class...
  1. RegisterNotification- void method for register notification 
  2. SqlDependency_OnChange- SqlDependency onchnage event, get fired when assigned SQL command produced a different 
  3. GetContacts- This is a method for return the changes happened on the server, here our new inserted contact data 
Code Ref
  1. using Microsoft.AspNet.SignalR;  
  2. using System;  
  3. using System.Collections.Generic;  
  4. using System.Configuration;  
  5. using System.Data.SqlClient;  
  6. using System.Linq;  
  7. using System.Web;  
  8.   
  9. namespace SignalRDemo  
  10. {  
  11.     public class NotificationComponent  
  12.     {  
  13.         //Here we will add a function for register notification (will add sql dependency)  
  14.         public void RegisterNotification(DateTime currentTime)  
  15.         {  
  16.             string conStr = ConfigurationManager.ConnectionStrings["sqlConString"].ConnectionString;  
  17.             string sqlCommand = @"SELECT [ID],[Name] from [dbo].[tblEmployee] where [AddedOn] > @AddedOn";  
  18.             //you can notice here I have added table name like this [dbo].[Contacts] with [dbo], its mendatory when you use Sql Dependency  
  19.             using (SqlConnection con = new SqlConnection(conStr))  
  20.             {  
  21.                 SqlCommand cmd = new SqlCommand(sqlCommand, con);  
  22.                 cmd.Parameters.AddWithValue("@AddedOn", currentTime);  
  23.                 if (con.State != System.Data.ConnectionState.Open)  
  24.                 {  
  25.                     con.Open();  
  26.                 }  
  27.                 cmd.Notification = null;  
  28.                 SqlDependency sqlDep = new SqlDependency(cmd);  
  29.                 sqlDep.OnChange += sqlDep_OnChange;  
  30.                 //we must have to execute the command here  
  31.                 using (SqlDataReader reader = cmd.ExecuteReader())  
  32.                 {  
  33.                     // nothing need to add here now  
  34.                 }  
  35.             }  
  36.         }  
  37.   
  38.         void sqlDep_OnChange(object sender, SqlNotificationEventArgs e)  
  39.         {  
  40.             //or you can also check => if (e.Info == SqlNotificationInfo.Insert) , if you want notification only for inserted record  
  41.             if (e.Type == SqlNotificationType.Change)  
  42.             {  
  43.                 SqlDependency sqlDep = sender as SqlDependency;  
  44.                 sqlDep.OnChange -= sqlDep_OnChange;  
  45.   
  46.                 //from here we will send notification message to client  
  47.                 var notificationHub = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();  
  48.                 notificationHub.Clients.All.notify("added");  
  49.                 //re-register notification  
  50.                 RegisterNotification(DateTime.Now);  
  51.             }  
  52.         }  
  53.   
  54.         public List<tblEmployee> GetData(DateTime afterDate)  
  55.         {  
  56.             using (SignalRDBEntities dc = new SignalRDBEntities())  
  57.             {  
  58.                 return dc.tblEmployees.Where(a => a.AddedOn > afterDate).OrderByDescending(a => a.AddedOn).ToList();  
  59.             }  
  60.         }  
  61.     }  

Code Description
 
The details code is explained using comment lines.
 
Step10

Add a new Controller named "HomeController.cs". Here I have added "Index" Action into "Home" Controller.

Code Ref
  1. public ActionResult Index()  
  2.         {  
  3.             return View();  
  4.         } 
Step11
 
Then create one view for home controller.
Code Ref
  1. @{  
  2.     ViewBag.Title = "Home";  
  3. }  
  4.   
  5. <h2>Index</h2>  
  6.   
  7.   
  8. <a target="_blank" href="Add/">Go To Notification page>></a> 
Code Description

This View is only for home page. 
 
Step12

Add another action in HomeController to fetch Employee data.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.Mvc;  
  6.   
  7. namespace SignalRDemo.Controllers  
  8. {  
  9.     public class HomeController : Controller  
  10.     {  
  11.         //  
  12.         // GET: /Home/  
  13.         public ActionResult Index()  
  14.         {  
  15.             return View();  
  16.         }  
  17.   
  18.         public JsonResult GetNotifications()  
  19.         {  
  20.             var notificationRegisterTime = Session["LastUpdated"] != null ? Convert.ToDateTime(Session["LastUpdated"]) : DateTime.Now;  
  21.             NotificationComponent NC = new NotificationComponent();  
  22.             var list = NC.GetData(notificationRegisterTime);  
  23.   
  24.             //update session here for get only new added contacts (notification)  
  25.             Session["LastUpdate"] = DateTime.Now;  
  26.             return new JsonResult { Data = list, JsonRequestBehavior = JsonRequestBehavior.AllowGet };  
  27.         }  
  28.   
  29.     }  

Code Description

The details code is explained using comment lines. 
 
Step13

Add and update _Layout.cshtml for showing notification.

Code Ref
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="utf-8" />  
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">  
  6.     <title>@ViewBag.Title - Satyaprakash Jquery and SignalR Intro</title>  
  7.     <link href="~/Content/bootstrap.css" rel="stylesheet" />  
  8.     <script src="~/Scripts/modernizr-2.6.2.js"></script>  
  9. </head>  
  10. <body>  
  11.     <div class="navbar navbar-inverse navbar-fixed-top">  
  12.         <div class="container">  
  13.             <div class="navbar-header">    
  14.                   
  15.                 <span class="noti glyphicon glyphicon-globe"><span class="count"> </span></span>  
  16.                     <div class="noti-content">  
  17.                         <div class="noti-top-arrow"></div>  
  18.                         <ul id="notiContent"></ul>  
  19.                     </div>  
  20.                 @Html.ActionLink("Satyaprakash Jquery and SignalR""Index""Home"nullnew { @class = "navbar-brand" })  
  21.             </div>  
  22.         </div>  
  23.     </div>  
  24.     <div class="container body-content">  
  25.         @RenderBody()  
  26.         <hr />  
  27.     </div>      
  28.         @* Add Jquery Library *@  
  29.         <script src="~/Scripts/jquery-2.2.3.min.js"></script>  
  30.         <script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script>  
  31.         <script src="/signalr/hubs"></script>  
  32.         <script src="~/Scripts/bootstrap.min.js"></script>  
  33.         @* Add css  *@  
  34.     <link href="~/Content/bootstrap.css" rel="stylesheet" />      
  35.       
  36.     <style type="text/css">  
  37.         /*Added css for design notification area, you can design by your self*/  
  38.         /* COPY css content from youtube video description*/  
  39.         .noti-content{  
  40.             position:fixed;  
  41.             right:100px;  
  42.             background:yellow;  
  43.             color:blue;  
  44.             font-size:medium;  
  45.             font-style:oblique;  
  46.             font-family:Arial;  
  47.             border-radius:4px;  
  48.             top:47px;  
  49.             width:440px;  
  50.             display:none;  
  51.             border: 1px solid #9E988B;  
  52.         }  
  53.         ul#notiContent{  
  54.             max-height:200px;  
  55.             overflow:auto;  
  56.             padding:0px;  
  57.             margin:0px;  
  58.             padding-left:20px;  
  59.         }  
  60.             ul#notiContent li {  
  61.                 margin: 3px;  
  62.                 padding: 6px;  
  63.                 background: #FF6600;  
  64.             }  
  65.             .noti-top-arrow{  
  66.                 border-color:transparent;  
  67.                 border-bottom-color:#F5DEB3;  
  68.                 border-style:dashed dashed solid;  
  69.                 border-width: 0 8.5px 8.5px;  
  70.                 position:absolute;  
  71.                 right:32px;  
  72.                 top:-8px;  
  73.             }  
  74.         span.noti {  
  75.             color:lightgreen;  
  76.             margin: 15px;  
  77.             position: fixed;  
  78.             right: 100px;  
  79.             font-size: 30px;  
  80.             cursor: pointer;  
  81.         }  
  82.         span.count {  
  83.             position:fixed;  
  84.             top: -1px;  
  85.             /*color:white;*/  
  86.         }  
  87.         /*.noti:hover { 
  88.             color:white; 
  89.         }*/  
  90.     </style>     
  91.       
  92.         @* Add jquery code for Get Notification & setup signalr *@  
  93.         <script type="text/javascript">  
  94.             $(function () {  
  95.                 // Click on notification icon for show notification  
  96.                 $('span.noti').click(function (e) {  
  97.                     debugger;  
  98.                     e.stopPropagation();  
  99.                     $('span.noti').css("color""lightgreen");  
  100.                     $('span.count').hide();  
  101.                     $('.noti-content').show();  
  102.                     var count = 0;  
  103.                     count = parseInt($('span.count').html()) || 0;  
  104.                     count++;  
  105.                     // only load notification if not already loaded  
  106.                     if (count > 0) {  
  107.                         updateNotification();                         
  108.                     }  
  109.                     $('span.count'this).html(' ');  
  110.                 })  
  111.                 // hide notifications  
  112.                 $('html').click(function () {  
  113.                     $('.noti-content').hide();  
  114.                 })  
  115.                 // update notification  
  116.                 function updateNotification() {  
  117.                     $('#notiContent').empty();  
  118.                     $('#notiContent').append($('<li>Loading...</li>'));  
  119.                     $.ajax({  
  120.                         type: 'GET',  
  121.                         url: '/home/GetNotifications',  
  122.                         success: function (response) {  
  123.                             debugger;  
  124.                             $('#notiContent').empty();  
  125.                             if (response.length == 0) {  
  126.                                 $('#notiContent').append($('<li>Currently You Have No New Notifications.</li>'));  
  127.                             }  
  128.                             $.each(response, function (index, value) {  
  129.                                 $('#notiContent').append($('<li>The User , ' + value.Name+' ' +'Of ID' + ' (' + value.ID + ') Is Written   
  130.   
  131. Something.</li>'));  
  132.                             });  
  133.                         },  
  134.                         error: function (error) {  
  135.                             console.log(error);  
  136.                         }  
  137.                     })  
  138.                 }  
  139.                 // update notification count  
  140.                 function updateNotificationCount() {  
  141.                     $('span.count').show();  
  142.                     var count = 0;  
  143.                     count = parseInt($('span.count').html()) || 0;  
  144.                     count++;  
  145.                     $('span.noti').css("color""white");  
  146.                     $('span.count').css({ "background-color""red""color""white" });  
  147.                     $('span.count').html(count);  
  148.                       
  149.                 }  
  150.                 // signalr js code for start hub and send receive notification  
  151.                 var notificationHub = $.connection.notificationHub;  
  152.                 $.connection.hub.start().done(function () {  
  153.                     console.log('Notification hub started');  
  154.                 });  
  155.                 //signalr method for push server message to client  
  156.                 notificationHub.client.notify = function (message) {  
  157.                     if (message && message.toLowerCase() == "added") {  
  158.                         updateNotificationCount();  
  159.                     }  
  160.                 }  
  161.             })  
  162.         </script>  
  163.       
  164. </body>  
  165. </html> 
Code Description

The details code is explained using comment lines.

Step14

Update global.asax.cs to start, stop SQL dependency

Code Ref
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Configuration;  
  4. using System.Data.SqlClient;  
  5. using System.Linq;  
  6. using System.Web;  
  7. using System.Web.Http;  
  8. using System.Web.Mvc;  
  9. using System.Web.Routing;  
  10.   
  11. namespace SignalRDemo  
  12. {  
  13.     // Note: For instructions on enabling IIS6 or IIS7 classic mode,   
  14.     // visit http://go.microsoft.com/?LinkId=9394801  
  15.     public class MvcApplication : System.Web.HttpApplication  
  16.     {  
  17.         string con = ConfigurationManager.ConnectionStrings["sqlConString"].ConnectionString;  
  18.         protected void Application_Start()  
  19.         {  
  20.             AreaRegistration.RegisterAllAreas();  
  21.   
  22.            // WebApiConfig.Register(GlobalConfiguration.Configuration);  
  23.            // FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);  
  24.             RouteConfig.RegisterRoutes(RouteTable.Routes);  
  25.             //here in Application Start we will start Sql Dependency  
  26.             SqlDependency.Start(con);  
  27.         }  
  28.   
  29.         protected void Session_Start(object sender, EventArgs e)  
  30.         {  
  31.             NotificationComponent NC = new NotificationComponent();  
  32.             var currentTime = DateTime.Now;  
  33.             HttpContext.Current.Session["LastUpdated"] = currentTime;  
  34.             NC.RegisterNotification(currentTime);  
  35.         }  
  36.   
  37.   
  38.         protected void Application_End()  
  39.         {  
  40.             //here we will stop Sql Dependency  
  41.             SqlDependency.Stop(con);  
  42.         }  
  43.     }  

Code Description

The details code is explained using comment lines.

Step15

Now add a new Controller/Action To add Notification Data.
  1. I have created AddController.cs in Controller directory.
  2. Add action named "Index"
Code Ref:
  1. public ActionResult Index()  
  2.        {  
  3.            return View();  
  4.        } 
Step16

Create View for Index action to add Employee Notification Details.

Code Ref
  1. @model SignalRDemo.tblEmployee  
  2.   
  3. @{  
  4.     ViewBag.Title = "Add Notification";  
  5. }  
  6.   
  7. <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>  
  8.   
  9. <link href="~/App_Content/CSS/bootstrap.min.css" rel="stylesheet" />  
  10. <link href="~/App_Content/CSS/font-awesome.min.css" rel="stylesheet" />  
  11.   
  12. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">  
  13. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>  
  14. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>  
  15. <script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js">  
  16.   
  17. </script>  
  18.   
  19. <style>  
  20.     .button {  
  21.         background-color: #4CAF50;  
  22.         border: none;  
  23.         color: white;  
  24.         padding: 15px 32px;  
  25.         text-align: center;  
  26.         text-decoration: none;  
  27.         display: inline-block;  
  28.         font-size: 16px;  
  29.         margin: 4px 2px;  
  30.         cursor: pointer;  
  31.     }  
  32.   
  33.     .button4 {  
  34.         border-radius: 9px;  
  35.     }  
  36.     .control{  
  37.         width:459px;  
  38.         height:145px;  
  39.     }  
  40. </style>  
  41.   
  42. <h2>Notification</h2>  
  43.   
  44. @using (Html.BeginForm(FormMethod.Post))  
  45. {  
  46.     @Html.ValidationSummary(true)  
  47.   
  48.     <fieldset>  
  49.         <legend>Notification</legend>  
  50.   
  51.         <div class="editor-label">  
  52.             @Html.LabelFor(model => model.Name)  
  53.         </div>  
  54.         <div class="editor-field">  
  55.             @Html.TextAreaFor(model => model.Name, new { id = "ValidateNametextbox", @class = "form-control" })  
  56.             @Html.ValidationMessageFor(model => model.Name)  
  57.         </div>  
  58.   
  59.      
  60.         <p>  
  61.             <input id="SubmitProject" class="button button4" type="submit" value="Notify" onclick="saveToFile()" />  
  62.         </p>  
  63.     </fieldset>  
  64. }  
  65. <script type="text/javascript">  
  66.     function saveToFile() {  
  67.             if ($("#ValidateNametextbox").val() == "") {  
  68.                 alert("Comment Section should not be empty!!");  
  69.             }  
  70.             else {  
  71.                 alert("Go To Home Page of Client Browser.");  
  72.             }  
  73.     };  
  74. </script> 
Code Description

Here I have added some mvc controls like textarea and button.
  1. @using (Html.BeginForm(FormMethod.Post))  
  2. {  
  3.     @Html.ValidationSummary(true)  
  4.   
  5.     <fieldset>  
  6.         <legend>Notification</legend>  
  7.   
  8.         <div class="editor-label">  
  9.             @Html.LabelFor(model => model.Name)  
  10.         </div>  
  11.         <div class="editor-field">  
  12.             @Html.TextAreaFor(model => model.Name, new { id = "ValidateNametextbox", @class = "form-control" })  
  13.             @Html.ValidationMessageFor(model => model.Name)  
  14.         </div>  
  15.   
  16.      
  17.         <p>  
  18.             <input id="SubmitProject" class="button button4" type="submit" value="Notify" onclick="saveToFile()" />  
  19.         </p>  
  20.     </fieldset>  

Step17

Add Post action for Index and add code to insert Employee.

Code Ref
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.Mvc;  
  6.   
  7. namespace SignalRDemo.Controllers  
  8. {  
  9.     public class AddController : Controller  
  10.     {  
  11.         //  
  12.         // GET: /Add/  
  13.   
  14.         public ActionResult Index()  
  15.         {  
  16.             return View();  
  17.         }  
  18.   
  19.         [HttpPost]  
  20.         public ActionResult Index(tblEmployee model)  
  21.         {  
  22.             SignalRDBEntities entity = new SignalRDBEntities();  
  23.             model.AddedOn = DateTime.Now;  
  24.             entity.tblEmployees.Add(model);  
  25.             entity.SaveChanges();  
  26.             return View();  
  27.         }  
  28.   
  29.     }  

Code Description

Here I have added entityname "SignalRDBEntities" and using autogenerated class tblEmployee object model we added data on datetime when you insert data and for entity class object we inserted data on remaining table columns. 
  1. SignalRDBEntities entity = new SignalRDBEntities(); 
The below two line has the main role to insert records. 
  1. entity.tblEmployees.Add(model);  
  2. entity.SaveChanges(); 
Step18

Here I configured my text area heading with "Add Comments." So, we should do an auto-generated class "tblEmployee.cs".

Code Ref
  1. //------------------------------------------------------------------------------  
  2. // <auto-generated>  
  3. //    This code was generated from a template.  
  4. //  
  5. //    Manual changes to this file may cause unexpected behavior in your application.  
  6. //    Manual changes to this file will be overwritten if the code is regenerated.  
  7. // </auto-generated>  
  8. //------------------------------------------------------------------------------  
  9.   
  10. namespace SignalRDemo  
  11. {  
  12.     using System;  
  13.     using System.Collections.Generic;  
  14.     using System.ComponentModel.DataAnnotations;  
  15.       
  16.     public partial class tblEmployee  
  17.     {  
  18.         public int ID { getset; }  
  19.         [Display(Name = "Add Comments")]  
  20.         public string Name { getset; }  
  21.         public Nullable<System.DateTime> AddedOn { getset; }  
  22.     }  

Code Description

I added Display attribute to configure. So, you should add the namespace. 
  1. using System.ComponentModel.DataAnnotations;
  2.  
  3. [Display(Name = "Add Comments")]  
  4. public string Name { getset; } 
Note

Sometimes due to more temporary and cache files the count will be a bit off. So, You should clean the solution and clean the project then Run....
 
 
 
OUTPUT

Home Page,



Then Notification insert page,



Add some notification text In Notification insert page



Then, it will show u a popup to go to home page to see the notification count as well as notification text.




You can see when there is no new notifiation, then the notification color is light green but when any new notification comes, the notification color is changed to white. Then, after clicking on the notification, the details will be shown and notification color is changed to light green. You can see some features are the same as Facebook Notification.




You can insert the data via one browser and get the updated notification on the homepage in the other browser also. The result will be shown in the same instance and different instance of same browser or different browser.

You can check the data inserted in the table.



In GIF -

Up Next
    Ebook Download
    View all
    Learn
    View all