[英]How to send text from textbox with SignalR from client to hub
I'm struggling with a beginner problem. 我正在努力解决初学者的问题。 After hours asking google I didn't find the right answer (maybe there is no good explanation in German).
几个小时后问谷歌,我没有找到正确的答案(也许德语没有很好的解释)。
I created a hub. 我创建了一个集线器。 On my client I want to send a text which is filled in a textbox to my hub.
在我的客户端上,我想将文本框中填写的文本发送到集线器。 But it doesn't work.
但这是行不通的。 i tried every tutorial from the web.
我尝试了网上的所有教程。 anybody can help me?
有人可以帮助我吗?
here is my code: 这是我的代码:
Hub Class: 集线器类别:
class myhub : Hub
{
public void sendPatName (string name)
{
Clients.All.broadcastMessage(name);
Console.WriteLine (name);
}
}
Client Side code 客户端代码
var hubConnection = new HubConnection("http://192.168.188.33:8080");
IHubProxy PatScreenProxy = hubConnection.CreateHubProxy("myhub");
//this doesn't work
// PatScreenProxy.On<string>("boradcastMessage", (param) => this.Invoke((Action)(() => textBox2.AppendText(string.Format("{0}", param)))));
hubConnection.Start().Wait();
string PatName = this.txtbLastname.Text;
PatScreenProxy.Invoke("sendPatName", PatName);
when I try 当我尝试
PatScreenProxy.Invoke("sendPatName", "PatName");
I receive the string PatName at my hub. 我在中心收到字符串PatName。
How can I send the content of my textbox? 如何发送文本框的内容?
I believe you problem is related to the line: 我相信您的问题与该行有关:
PatScreenProxy.Invoke("sendPatName", PatName);
Try to explicit convert it to string: 尝试将其显式转换为字符串:
PatScreenProxy.Invoke("sendPatName", PatName.ToString());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.