我想在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>: ' + encodedwhomid + '</li><li><strong>' + encodedlikes
+ '</strong>: ' +encodedpostid + '</li><li><strong>' + encodedtime
+ '</strong>: ' + encodedseen + '</li>');
};
答案 0 :(得分:0)
你试过吗?
wall.server.send(ViewBag.u,1,1,id,new Date(),false);
您已经在代码块中,不需要&#34; @&#34;或引用。