我有一个带静态方法的集线器,它向当前所有用户广播通知.
public class NotificationHub : Hub
{
private static string connString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();
[HubMethodName("sendNotifications")]
public static void SendNotifications()
{
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
context.Clients.All.updateNotifications();
}
}
Run Code Online (Sandbox Code Playgroud)
我需要从前端javascript中获取一些文本框输入,例如10038,这是userID并将其发送到服务器类,例如
public class NotificationRepository
{
private readonly string _connString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
public IEnumerable<Notifications> GetNotifications(int userID)
{
var notifications = new List<Notifications>();
using (var connection = new SqlConnection(_connString))
{
connection.Open();
using (var command = new SqlCommand(String.Format(@"SELECT [ID], [UserID], [Message] FROM [dbo].[Notification] WHERE [UserID] = {0}", userID), connection))
{
command.Notification = null;
var dependency = new …Run Code Online (Sandbox Code Playgroud)