2016-11-18 10 views
0

私はSignalRでViewbagを送信します。送信メソッドですが、サーバーハブのメソッドをヒットしたときに空の値を取得します。ビュー内のサーバーへSignalRのパラメータとしてViewbagを送信できませんSend

コール:

 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>'); 
     }; 

答えて

0

あなたは試したことがありますか?

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

あなたはすでにコードブロック内にありますが、 "@"や引用符は必要ありません。

+0

ありがとうKlinger。 –

関連する問題