Finding articles is always nice. This makes it a lot easier for the user to find the right content on your site. We'll put in a really simple yet effective search here.
Let's start by creating a second hub. In the Hubs
folder, add a class called SearchHub
and add the following code to it:
using System.Collections.Generic; using Chapter3.DAL; using Chapter3.Models.News; using Microsoft.AspNet.SignalR; namespace Chapter3.Hubs { public class SearchHub : Hub { ArticleContext _articleContext; public SearchHub() { _articleContext = new ArticleContext(); } public IEnumerable<Article> GetArticlesContaining(string phrase) { return _articleContext.GetArticlesContaining(phrase); } } }
Remember the _Layout.js
file we created where we didn't enter anything. Open it and enter the following code:
$(function () { var searchInput = document.getElementById("searchInput")...