locked
SignalR jquery function RRS feed

  • Question

  • Hello everyone,

    I am very new with signalR. In my asp.net mvc 5 project I need to use signalR. But I am failing to do that. Even I don't what is the reason behind this because I am new here. Can anyone please help me how can I resolve this ? Here is my code below :

    [HubName("statusLog")]
        public class StatusLogHub : Hub
        {
            //public void Hello()
            //{
            //    Clients.All.hello();
            //}
            [HubMethodName("sendExportStatus")]
            public static void SendExportStatus()
            {
                IHubContext context = GlobalHost.ConnectionManager.GetHubContext<StatusLogHub>();
                context.Clients.All.updateStatus();
            }
        }
    
    Controller:
    public ActionResult GetExportStatus()
            {
                EmailStatusLogRepository objEmailStatusRepository = new EmailStatusLogRepository();
                return PartialView("_exportedReportList", objEmailStatusRepository.GetExportStatus());
            }
    

    View:
    
    
    $("#btnEmail").click(function () {          
                tinyMCE.triggerSave(true, true);
                $('#emailform').submit();            
                $.ajax({
                    url: '@Url.Action("Email")',
                    type: "POST",
                    data: $('#emailform').serialize(),
                    dataType: "json",
                    traditional: true,
                   //SignalR
                    success: function () {
                        // Declare a proxy to reference the hub.
                        var notifications = $.connection.statusLog;
                       
                        notifications.client.updateStatus = function () {
                            getExportStatus()
    
                        };
                        // Start the connection.
                        $.connection.hub.start().done(function () {
                            alert("connection started")
                            getExportStatus();
                        }).fail(function (e) {
                            alert(e);
                        });
                    }
    
                });
                function getExportStatus() {
                    var tbl = $('#statusTable');
                    $.ajax({
                        url: '@Url.Action("GetExportStatus")',
                        contentType: 'application/html ; charset:utf-8',
                        type: 'GET',
                        dataType: 'html'
                    }).success(function (result) {
                        tbl.empty().append(result);
                    }).error(function () {
    
                    });
                }
            });

    It will be a great help for me. With Thanks.

    Monday, March 14, 2016 9:17 AM