无法在SignalR Send中将Viewbag作为参数发送

时间:2016-11-18 07:02:55

标签: c# html css asp.net-mvc-5

我想在signalR Send方法中发送Viewbag但是当它点击服务器中心方法时我得到空值请帮助。

在View中调用服务器:

       wall.server.send("@ViewBag.u",1,1,id,new Date(),false);

集线器:

  public void Send(object userId, int toWhomId, int likes, int postid, DateTime time, bool seen)
    {

   //
        //userId is emtpy here???


        // Call the broadcastMessage method to update clients.
        Clients.All.broadcastMessage(userId, toWhomId, likes, postid, time, seen);
    }

广播:

    $(function() {
        // Create a function that the hub can call to broadcast messages.
        wall.client.broadcastMessage = function (userId,toWhomId, likes, postid, time,seen) {
            var encodeduserid = $('<div />').text(userId).html();
            var encodedwhomid = $('<div />').text(toWhomId).html();
            var encodedlikes = $('<div />').text(likes).html();
            var encodedpostid = $('<div />').text(postid).html();
            var encodedtime = $('<div />').text(time).html();
            var encodedseen = $('<div />').text(seen).html();
            // Add the message to the page.
            $('#discussion').append('<li><strong>' + encodeduserid
                + '</strong>:&nbsp;&nbsp;' + encodedwhomid + '</li><li><strong>' +  encodedlikes
                + '</strong>:&nbsp;&nbsp;' +encodedpostid + '</li><li><strong>' + encodedtime
                + '</strong>:&nbsp;&nbsp;' + encodedseen  + '</li>');
        };

1 个答案:

答案 0 :(得分:0)

你试过吗?

  wall.server.send(ViewBag.u,1,1,id,new Date(),false);

您已经在代码块中,不需要&#34; @&#34;或引用。