Created
January 31, 2019 01:37
-
-
Save dcomartin/a12f75a6a1d3e3f3be30525cad712284 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.AspNetCore.SignalR; | |
namespace Practical.AspNetCore.SignalR | |
{ | |
public class AnnouncementController : Controller | |
{ | |
private IHubContext<MessageHub> _hubContext; | |
public AnnouncementController(IHubContext<MessageHub> hubContext) | |
{ | |
_hubContext = hubContext; | |
} | |
[HttpGet("/announcement")] | |
public IActionResult Index() | |
{ | |
return View(); | |
} | |
[HttpPost("/announcement")] | |
public async Task<IActionResult> Post([FromForm] string message) | |
{ | |
await _hubContext.Clients.All.SendAsync("ReceiveMessage", message); | |
return RedirectToAction("Index"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment