SignalR Hub method mapping mvc 5 serverside method. RRS feed

  • Question

  • User1000691596 posted

    Hello everyone,

    I developing an asp.net mvc 5 application where I need to use signalR. I have created the hub and I was able to connect with the hub. Now the main problem I'm facing how to map serverside methods with the hub. I am totally new with signalR if any can help me that will be a great help for me. Here is my code :

        public class StatusLogHub : Hub
            public void SendExportStatus()
                IHubContext context = GlobalHost.ConnectionManager.GetHubContext<StatusLogHub>();
    Repository : 
    public class EmailStatusLogRepository
            EMailDBContext _ctx = new EMailDBContext();
    //I need to show this lstEmailStatus list in real time.        
            public IEnumerable<EmailStatusLog> GetExportStatus()
                var lstEmailStatus = _ctx.emailStatusLogs.Where(x => x.IsActive == true && x.Date ==    DateTime.Now.ToString()).ToList();
                return lstEmailStatus;
    Controller :
    public ActionResult GetExportStatus()
                EmailStatusLogRepository objEmailStatusRepository = new EmailStatusLogRepository();
                return PartialView("_exportedReportList", objEmailStatusRepository.GetExportStatus());
     $("#btnExportStatus").click(function () {
                        url: '@Url.Action("GetExportStatus")',
                        contentType: 'application/html ; charset:utf-8',
                        type: 'GET',
                        dataType: 'html'
                    }).success(function () {
                        var connection = $.hubConnection();
                        var hub = connection.createHubProxy("statusLog");
                        hub.on("updateStatus", function (statusUpdated) {
                    // Declare a proxy to reference the hub.
            function getExportStatus() {
                var tbl = $('#statusTable');
                $(function (result) {
                }).error(function () {


    Wednesday, March 16, 2016 3:49 AM


  • User61956409 posted

    Hi moinulmithu,

    Firstly, You had better to learn the basic usage of ASP.NET SignalR, it will be helpful for you use ASP.NET SignalR in your MVC project.


    Secondly, could you explained more about your requirements?

    Besides, as I said in this thread you posted, you define a hub method named “sendExportStatus”, but you don’t call this hub method from clients.


    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 17, 2016 8:24 AM