title: ASP.NET MVC - Highlight the search term in search results
body: <p>Is it possible to highlight the search term in returned search results? For example:</p>
  
  <p>My <code>[HttpPost]</code> Action:</p>
  
  <pre><code>    public ActionResult ProductSearchForm(Product product)
      {
          return RedirectToAction("ProductResult", new { id = product.ITEMID });
      }
  
      public ActionResult ProductResult(string id)
      {
          var products = client.ProductSearch(id);
          return PartialView("_ProductResult", products);
      }
  </code></pre>
  
  <p>client.ProductSearch method (This is a web service, but that's irrelevant):</p>
  
  <pre><code>    public List&lt;string&gt; ProductSearch(string id)
      {
          List&lt;string&gt; products = context.Products.
              Where(x =&gt; x.ITEMID.StartsWith(id)).Select(x=&gt;x.ITEMID).ToList();
  
          return products;
      }
  </code></pre>
  
  <p>_ProductResult Partial View:</p>
  
  <pre><code>@foreach (var item in Model)
  {
     &lt;p&gt;@item.ITEMID&lt;/p&gt;
  }
  </code></pre>
  
  <p>As I use a <code>StartsWith</code> I'd like to highlight the search term in the search results. For example if I search for '123' and this returns 2 results. I'd like it to return something like so:</p>
  
  <pre><code>**123**456
  
  **123**45678
  </code></pre>
  
  <p>Or wrap the search term with a span that has a class, like so:</p>
  
  <pre><code>&lt;span class="highlighted"&gt;123&lt;/span&gt;456
  
  &lt;span class="highlighted"&gt;123&lt;/span&gt;45678
  </code></pre>
  
  <p>Then this class would have a CSS rule set where it sets the color to yellow for example.</p>
  
  <p>Is this possible?</p>