Book Image

SignalR Blueprints

By : Einar Ingerbrigsten
Book Image

SignalR Blueprints

By: Einar Ingerbrigsten

Overview of this book

Table of Contents (18 chapters)
SignalR Blueprints
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
9
Debugging or Troubleshooting
Index

Finding the needle in the haystack


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")...