简体   繁体   English

如何使用SignalR将文本框中的文本从客户端发送到集线器

[英]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.

相关问题 如何从websocket-sharp客户端发送文件到SignalR集线器? - How to Send File to SignalR hub From websocket-sharp Client? 将图像网址从SignalR集线器发送到javascript - Send image url to javascript from SignalR hub 通过Asp.Net MVC应用程序中托管的SignalR集线器从外部服务向Web客户端发送通知 - Send notification to web client from external service via SignalR hub hosted in Asp.Net MVC Application 如何从SignalR hub获取IOwinContext? - How to get IOwinContext from SignalR hub? 您如何从同一项目中的另一个类从 SignalR Hub 发送出去? - How do you send out from SignalR Hub from another class in the same project? 从AngularJS客户端到一个SignalR集线器的多个连接 - Multiple connections to one SignalR hub from AngularJS client SignalR,将对象从 HUB 传递到客户端(MVC C#) - SignalR, passing an object from the HUB to the Client (MVC C#) 从Signalr .net客户端调用集线器方法将引发异常 - Invoking hub method from signalr .net client throws exception SignalR - 从.NET客户端枚举可用的集线器和集线器方法 - SignalR - enumerate available hubs and hub methods from .NET client 来自客户端的集线器方法未在ASP.NET Core SignalR中调用 - Hub method from client is not invoking in ASP.NET Core SignalR
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM