2014-09-10 53 views
1

我目前正在设计一款游戏,需要从我的视图中检索一个值并将其发送到我的SingalR集线器。使用MVC,我想从我的cshtml视图中检索一个值并将其存储在我的SignalR中心

我想将从我的视图中检索到的值存储在我的集线器中的全局变量中。如下

例子:

查看

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

枢纽

int a; //global variable in hub 

public void retrieve(int num) //my method to store value 
{ 
    a=num; 
} 

回答

0

这是非常基本的,假设你已经连接到集线器。我认为该代码自己说明:

<script> 
    var num = @ViewBag.a; 

    //connect to hub here 

    proxy.server.retrieve(num); 
</script> 
相关问题