title: signalR global hub start connection in a view and use it in a partial view MVC
body: <p>I have start a connection with hub in a view and make it global for use the some connection in a partial view.
  But in a partial view the method is connection from hub and send the message, but is not received in other cliente.
  When I tired global variable and start again the hub connection in partial view, the messages have arrived as well.</p>
  
  <p>what's wrong in global start connection variable use?</p>
  
  <p>In hub I have:</p>
  
  <pre><code>    public void SendQuestionario(int id, string message, string userNameTo)
      {
  
          UserConnection connect = usersConnect.FirstOrDefault(x =&gt; x.ConnectionID == userNameTo);
  
          if (connect != null)
          {
  
              Clients.User(connect.UserName).addNewMessageToPageQuestionario(id, message);
  
  
          }
  </code></pre>
  
  <p>In a view:</p>
  
  <pre><code>$(function () {
  
      window.chat = $.connection.chatHub;
  
  
      chat.client.notificacaoIAD = function (message) {
  
          alert(message);
  
      };
  
  
      chat.client.updateStatus = function (message) {
  
          alert(message);
  
          if (message == "Online") {
              $("#status").text("Online")
          }
          else
              $("#status").text("Offline")
  
      };
  
  
  
  
  window.hubReady=$.connection.hub.start().done(function () {
  
          alert("Connection succeeded");
  
  
          //verificar o status do user para a ligação
          chat.server.verificaStatus(userFrom, userTo);
  
  
      }).fail(function () {
  
          alert("Connection failed");
  
      });
  
  });
  </code></pre>
  
  <p>In partial view:</p>
  
  <p>$(function () {</p>
  
  <pre><code>//var chat = $.connection.chatHub;
  
  
      window.chat.client.addNewMessageToPageQuestionario = function (id, message) {
  
          alert(message);
  
          $("#responder_" + id).append(htmlEncode(message));
          //$("#content_" + id).html(message);
      };
  
  
  
  
  window.hubReady.done(function () {
  
  
          $(".sendmessage").click(function () {
  
  
              var id = $(this).attr('id');
  
  
              alert($("#resposta_" + id).val());
  
  
              window.chat.server.sendQuestionario(id, ($("#resposta_" + id).val()), nome);
  
              });
  
          }).fail(function () {
  
              alert("erro na conexão");
  
          });
  
     });
  
  
  
  
  public class ChatHub : Hub
  {
      public static List&lt;UserConnection&gt; usersConnect = new List&lt;UserConnection&gt;();
  
  
      public void SendOnline(string id, string mensagem)
  </code></pre>
  
  <p>{</p>
  
  <pre><code>    var context = GlobalHost.ConnectionManager.GetHubContext&lt;ChatHub&gt;();
  
  
  
         context.Clients.All.updateStatus(id, mensagem);
  
  
  }
  
  
      public void SendQuestionario(int id, string message, string userNameTo)
      {
  
          UserConnection connect = usersConnect.FirstOrDefault(x =&gt; x.ConnectionID == userNameTo);
  
          if (connect != null)
          {     
              Clients.User(connect.UserName).addNewMessageToPageQuestionario(id, message);
  
          }        
      }
  
  
  
      public override Task OnConnected()
      {
  
          string name = Context.User.Identity.Name;
          string id = Context.User.Identity.GetUserId();
  
          if (!usersConnect.Exists(x =&gt; x.UserName == name))
          {
              usersConnect.Add(new UserConnection { ConnectionID = id, UserName = name });
          }
  
          return base.OnConnected();
      }
  </code></pre>