title: Call Signalr method from Controller .Net Core 2.1
body: <p>I am trying to call a method in the signalr Hub class from an (ASP.NET Core) MVC Controller, but I cannot find an example online that shows how to.</p>
  
  <p><em>Note: There are lots of examples using older versions of signalr with the .Net Framework, but none that I can see that show how to do this in .Net Core.</em></p>
  
  <p>I need to pass an id from the an MVC Action Result directly through to my Hub, without passing the id to the page, and then having to get a client connection back through to the hub.</p>
  
  <pre><code>public class ChatHub : Hub
  { 
      public async Task DoSomething(int id)
      {            
          //// Something in here.
      }
  }
  
  
  
  public class HomeController : Controller
  {
      private readonly IHubContext&lt;ChatHub&gt; _hubContext;
  
      public HomeController(IHubContext&lt;ChatHub&gt; hubContext)
      {
          _hubContext = hubContext;
      }
  
      public async Task&lt;ActionResult&gt; Index(int id) 
      {
  
           //// Call the DoSomething method from here, passing the id across.
           await _hubContext.Clients.All.SendAsync("AddToGroup", groupId);
      }
  }
  </code></pre>
  
  <p>Is there a way to do this please?  (Or am I looking at this the wrong way, and is there a better way to achieve the same result?)</p>
  
  <p><em>Update:</em> If I pass the Id into the view, and then use JavaScript to call the Hub, this then calls the DoSomething method, so I can see it all hangs together correctly, but not when I try to call it in C#.</p>