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

  • SEARCH
  • Home
  • 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 7814851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:19:55+00:00 2026-06-02T05:19:55+00:00

I am trying to modify my search on a controller so that it is

  • 0

I am trying to modify my search on a controller so that it is able to count the number of matching results typed by the user in a search string.So that a user would search for a movie name and there was 1 matching film a message would say “1 movie matched your search criteria: ‘terminator’”.

So far this is my code , I have no errors and it searches the data fine but doesnt count the no of results.If anybody knows what I need to do in order to get the search to display a message then that would be very helpfull.The search facility works but I need to count how how many matches there are to the data & display a message if there are no results or if there are and how many.

Thanks

public ViewResult Index(string sortOrder, string searchString)
    {
        ViewBag.NamesSortParm = string.IsNullOrEmpty(sortOrder) ? "Name desc" : "";
        ViewBag.MoviesSortParm = sortOrder == "MovieID" ? "Name" : "Director";
        var Movies = from s in MoviesRepository.GetMovies ()
                    select s;
        if (!string.IsNullOrEmpty(searchString))
        {
            Movies = Movies.Where(s => s.Name.ToUpper().Contains(searchString.ToUpper())
                                   || s.Director.ToUpper().Contains(searchString.ToUpper()));
        int count = Movies.Count();
        if (count == 0)
        {
            ViewBag.Message = "No matches found";
        }
        else
        {
            ViewBag.Message = " Results";
        }  }
        switch (sortOrder)
        {
            case "Name":
                Movies = Shows.OrderByDescending(s => s.Name);
                break;
            case "Director":
                Movies = Movies.OrderByDescending(s => s.Director);
                break;
            default:
                Movies = Movies.OrderBy(s => s.Synopsis);
                break;
        }






        return View(Movies.ToList());





    }
  • 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-06-02T05:19:57+00:00Added an answer on June 2, 2026 at 5:19 am

    Looks like a typo to me. Replace this line:

    ViewBag.Message = " Results";
    

    with this:

    ViewBag.Message = count + " Results";
    

    Also, make sure to put ViewBag.Message in the View somewhere:

    <div> @ViewBag.Message </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a bash script that would modify all occurrences of a
I'm trying to modify some code that returns results from the database. Currently the
Hi I'm trying to modify a web page so that it loads faster. Since
I've been trying to modify the AuditTrail code so that it does not copy
I'm trying to modify the text of a Label component that I already placed
I am trying to create a system which would be able to find users
I'm trying and failing to use an ExpressionVisitor to modify an expression that calls
I'm trying to write a script for Greasemonkey to modify Google Instant results. I
I am trying to modify the output stream to search/replace some XHTML tags returned
I'm trying to modify the Orchard.Search part with the search form and button to

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.