使用MVC时,我想从cshtml视图中检索一个值,并将其存储在SignalR hub中

使用MVC时,我想从cshtml视图中检索一个值,并将其存储在SignalR hub中,signalr,postback,Signalr,Postback,我目前正在设计一个游戏,需要从我的视图中检索一个值并将其发送到我的SingalR hub 我想将从视图检索到的值存储在中心的全局变量中 示例如下: 查看 <html> Viewbag.a=1 //the value i want to send to the hub <html> 这是非常基本的,假设你已经连接到你的中心。我认为代码本身就说明了问题: <script> var num = @ViewBag.a; //connect

我目前正在设计一个游戏,需要从我的视图中检索一个值并将其发送到我的SingalR hub

我想将从视图检索到的值存储在中心的全局变量中

示例如下:

查看

<html>
    Viewbag.a=1 //the value i want to send to the hub
<html>

这是非常基本的,假设你已经连接到你的中心。我认为代码本身就说明了问题:

<script>
    var num = @ViewBag.a;

    //connect to hub here

    proxy.server.retrieve(num);
</script>

var num=@ViewBag.a;
//在这里连接到集线器
proxy.server.retrieve(num);
<script>
    var num = @ViewBag.a;

    //connect to hub here

    proxy.server.retrieve(num);
</script>