Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7437549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:24:58+00:00 2026-05-29T10:24:58+00:00

Is it possible to highlight the search term in returned search results? For example:

  • 0

Is it possible to highlight the search term in returned search results? For example:

My [HttpPost] Action:

    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);
    }

client.ProductSearch method (This is a web service, but that’s irrelevant):

    public List<string> ProductSearch(string id)
    {
        List<string> products = context.Products.
            Where(x => x.ITEMID.StartsWith(id)).Select(x=>x.ITEMID).ToList();

        return products;
    }

_ProductResult Partial View:

@foreach (var item in Model)
{
   <p>@item.ITEMID</p>
}

As I use a StartsWith 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:

**123**456

**123**45678

Or wrap the search term with a span that has a class, like so:

<span class="highlighted">123</span>456

<span class="highlighted">123</span>45678

Then this class would have a CSS rule set where it sets the color to yellow for example.

Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:24:59+00:00Added an answer on May 29, 2026 at 10:24 am

    You can pass “ID” to Partial view, then replace it

    public ActionResult ProductResult(string id)
    {
        var products = client.ProductSearch(id);
        ViewData["ID"] = id;
        return PartialView("_ProductResult", products);
    }
    

    In _ProductResult Partial View,

    @foreach (var item in Model)
    {
        <p>@Html.Raw(@item.ITEMID.Replace((string)ViewData["ID"], "<span class='highlighted'>" + (string)ViewData["ID"] + "</span>")) </p>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to perform an action when a UITableViewCell is highlighted? For example
Possible Duplicate: highlighting search results in php/mysql I am doing a search with a
I'm using the jquery.highlight plugin: http://code.google.com/p/gce-empire/source/browse/trunk/jquery.highlight.js?r=2 I'm using it to highlight search results. The
Possible Duplicate: How to highlight the results of a text in a gridview? I've
Is it possible to highlight the modifications in one text paragraph from the other?
Is it possible for TextMate to syntax highlight the opening and closing tags of
Does anyone know how or if its possible for Visual Studio 2008 to highlight
Possible Duplicate: Highlight keywords in a paragraph I have been struggling with the idea
Is it possible to highlight a cell, let's say red, with certain criteria. One
In VB.Net, is it possible to highlight ALL instances of a phrase instead of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.