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 6139815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:02:20+00:00 2026-05-23T18:02:20+00:00

I am trying to implement search functionality on a list of customers, the functionality

  • 0

I am trying to implement search functionality on a list of customers, the functionality is detailed in this tutorial on the Asp.Net site,

http://www.asp.net/entity-framework/tutorials/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application

In my controller i have the following

public ViewResult Index(string sortOrder, string searchString)
    {
        ViewBag.CustomerNameSortParm = String.IsNullOrEmpty(sortOrder) ? "CustomerName desc" : "";
        ViewBag.PrimaryContactNameSortParm = sortOrder == "PrimaryContactName" ? "PrimaryContactName desc" : "PrimaryContactName";
        var cust = repository.Customers;

        if (!String.IsNullOrEmpty(searchString))
        {
            cust = cust.Where(c => c.CustomerName.ToUpper().Contains(searchString.ToUpper())
                                   || c.PrimaryContactName.ToUpper().Contains(searchString.ToUpper()));
        }

        switch (sortOrder)
        {
            case "CustomerName desc":
                cust = repository.Customers.OrderByDescending(s => s.CustomerName);
                break;
            case "PrimaryContactName":
                cust = repository.Customers.OrderBy(s => s.PrimaryContactName);
                break;
            case "PrimaryContactName desc":
                cust = repository.Customers.OrderByDescending(s => s.PrimaryContactName);
                break;
            default:
                cust = repository.Customers.OrderBy(s => s.CustomerName);
                break;
        }

        return View(cust.ToList());
    }

The if statement checks the value and should use the LINQ, WHERE statement to filter the list,

I have the textbox setup in the view like

@using (Html.BeginForm())
{
<p>
    Find by name: @Html.TextBox("SearchString") &nbsp;
    <input type="submit" value="Search" /></p>
}

However when i enter a customer name the results are not filtered, i am using SQL Server 2008 R2, has anyone else encountered this issue? is there anything else required to get the Contains method working?

And advice is appreciated?

Liam

  • 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-23T18:02:21+00:00Added an answer on May 23, 2026 at 6:02 pm

    In the sort order switch you re-set the cust variable with the repository.Customers. You should use the cust variable instead to apply the sorting on the filtered set.

    switch (sortOrder)
            {
                case "CustomerName desc":
                    cust = cust.OrderByDescending(s => s.CustomerName);
                    break;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement a web search functionality on a MySQL database using
I was currently at this site which shows how to implement business search using
I'm trying to implement search result highlighting for pdfs in a web app. I
I am trying to implement an internal search for my website that can point
I'm trying to implement something like this: <div> <table> <thead> <tr> <td>Port name</td> <td>Current
I am trying to implement customized search in my application. The table structure is
While in search of trying to implement unique key validations for my db using
I'm trying to implement a Full Text Search. I'm using FREETEXT and I get
Hi I'm trying to implement jquery token input according to railscasts #258 http://railscasts.com/episodes/258-token-fields Where
All I am currently trying implement something along the lines of dim l_stuff as

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.