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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:55:02+00:00 2026-06-03T12:55:02+00:00

I am trying to create a search function that allows the user to search

  • 0

I am trying to create a search function that allows the user to search a column that is specified by a dropdown, I have been able to get the search to work but only by using a specific column and a contains method. Can anyone help?

Below I have included my controller and my view, please let me know if you need any other code. Thanks for your time and help!

I am almost positive that this is the code that I have to alter to use the dropdown to search instead of a specific column.

if (!String.IsNullOrEmpty(searchString))
            {
                IAMP = IAMP.Where(p => p.PA.ToUpper().Contains(searchString.ToUpper())); 
            }

Controller

 public class PaController : Controller
    {
        PaEntities db = new PaEntities();

        // Index Method 
        public ViewResult Index(string CurrentField, string sortField, string sortOrder, string currentFilter, string searchString, int? page, string Versions, string VPS, string Directors, string IAMP_SEARCH)
        {
            ViewBag.CurrentOrder = sortOrder = String.IsNullOrEmpty(sortOrder) ? "asc" : sortOrder; // Provides the order to sort
            ViewBag.CurrentField = sortField = String.IsNullOrEmpty(sortField) ? "IAMP_PK" : sortField; // Provides the field to sort

            var IAMP = from p in db.iamp_mapping select p;
            var ISER = from s in db.iamp_search_string select s;

            if (Versions != null && Versions != String.Empty) // Version Dropdown Sort Function     
            {
                IAMP = IAMP.Where(v => v.VERSION.Contains(Versions));
            }

            var VIAMP = from x in db.version_number select x;
            var VPIAMP = from v in db.vp_table select v;
            var DIAMP = from d in db.director_table select d;

            ViewData["SelectedVersion"] = Versions;
            ViewData["Versions"] = new SelectList(VIAMP.Select(x => x.VERSION));
            ViewData["VPS"] = new SelectList(VPIAMP.Select(x => x.VP));
            ViewData["Directors"] = new SelectList(DIAMP.Select(x => x.DIRECTOR));
            ViewData["currentFilter"] = currentFilter;
            ViewData["IAMP_SEARCH"] = IAMP_SEARCH;
            ViewData["IAMP_SEARCH"] = new SelectList(ISER.Select(x => x.IAMP_SEARCH));


            if (Request.HttpMethod == "GET") {

                searchString = currentFilter; //sets the currentFilter equal to Searchstring
                IAMP_SEARCH = sortField;
            }
            else {
                page = 1;                   // defaults to page 1
            }
            ViewBag.CurrentFilter = searchString; // Provides the view with the current filter string

            if (!String.IsNullOrEmpty(searchString))
            {
                IAMP = IAMP.Where(p => p.PA.ToUpper().Contains(searchString.ToUpper())); 
            }

            switch (sortField) {

                default: IAMP = sortOrder == "asc" ? IAMP.OrderBy(p => p.PA) : IAMP.OrderByDescending(p => p.PA); break;
                case "VERSION": IAMP = sortOrder == "asc"? IAMP.OrderBy(p => p.VERSION) : IAMP.OrderByDescending(p => p.VERSION); break;
                case "MAJOR_PROGRAM": IAMP = sortOrder == "asc" ? IAMP.OrderBy(p => p.MAJOR_PROGRAM) : IAMP.OrderByDescending(p => p.MAJOR_PROGRAM); break;
                case "INVESTMENT_AREA": IAMP = sortOrder == "asc" ? IAMP.OrderBy(p => p.INVESTMENT_AREA) : IAMP.OrderByDescending(p => p.INVESTMENT_AREA); break;
                case "VP": IAMP = sortOrder == "asc" ? IAMP.OrderBy(p => p.VP) : IAMP.OrderByDescending(p => p.VP); break;
                case "DIRECTOR": IAMP = sortOrder == "asc" ? IAMP.OrderBy(p => p.DIRECTOR) : IAMP.OrderByDescending(p => p.DIRECTOR); break;
            }


            int pageSize = 15; // number of records shown on page view
            int pageNumber = (page ?? 1); // start page number



            return View(IAMP.ToPagedList(pageNumber, pageSize)); // uses pagedList method to return correct page values
        }

VIEW

@model PagedList.IPagedList<DBFirstMVC.Models.iamp_mapping>


@{
    ViewBag.Title = "Index";

}

@using PagedList;


<h2 class="corporate sifr">PA Mapping</h2>



@using (Html.BeginForm())
{
    <p>
        Show Version: @Html.DropDownList("Versions","All")
        <input type = "submit" value = "Go" />
    </p>

}

@using (Html.BeginForm())
{
    <div class="lefty">
        Find by @Html.DropDownList("IAMP_SEARCH","All"): @Html.TextBox("SearchString")
        <input type = "submit" value = "Search" />
    </div>

}

<div class="righty">
    @Html.ActionLink("Add a new PA to the database", "Create")
</div>
<br /><br />

<div>
    <div class="lefty">
    Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
    of @Model.PageCount
    &nbsp;&nbsp;&nbsp;&nbsp;
    @if (Model.HasPreviousPage)
    {
        @Html.ActionLink("<<", "", new { page = 1, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter, Versions = ViewBag.SelectedVersion   })
        @Html.Raw(" ");
        @Html.ActionLink("< Prev", "", new { page = Model.PageNumber - 1, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter, Versions = ViewBag.SelectedVersion })
    }
    else
    {
        @:<<
        @Html.Raw(" ");
        @:< Prev
    }

    @if (Model.HasNextPage)
    {
        @Html.ActionLink("Next >", "", new { page = Model.PageNumber + 1, sortOrder = ViewBag.CurrentSort, currentFilter=ViewBag.CurrentFilter, Versions = ViewBag.SelectedVersion  })
        @Html.Raw(" ");
        @Html.ActionLink(">>", "", new { page = Model.PageCount, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter, Versions = ViewBag.SelectedVersion })
    }
    else
    {
        @:Next >
        @Html.Raw(" ")
        @:>>
    }
    </div>
    <div class="righty">
    Showing Records @Model.FirstItemOnPage to @Model.LastItemOnPage from @Model.TotalItemCount
    </div>
</div>


<table>
    <tr>
        <th>
            @Html.ActionLink("PA", "", new { sortOrder = ViewBag.currentOrder == "asc" ? "desc" : "asc", sortField = "PA", Versions = ViewBag.SelectedVersion })
            @if (ViewBag.currentOrder == "asc" && ViewBag.CurrentField == "PA"){ <img src="../../Images/ico_tablesortoffset_asc.gif" alt = "table sort arrow asc"/>}
            @if (ViewBag.currentOrder == "desc" && ViewBag.CurrentField == "PA"){ <img src="../../Images/ico_tablesortoffset_desc.gif" alt = "table sort arrow desc"/>}                                                                                           
        </th>
        <th>        
            @Html.ActionLink("MAJOR PROGRAM", "", new { sortOrder = ViewBag.currentOrder == "asc" ? "desc" : "asc", sortField = "MAJOR_PROGRAM", Versions = ViewBag.SelectedVersion })
            @if (ViewBag.currentOrder == "asc" && ViewBag.CurrentField == "MAJOR_PROGRAM"){ <img src="../../Images/ico_tablesortoffset_asc.gif" alt = "table sort arrow asc" />}
            @if (ViewBag.currentOrder == "desc" && ViewBag.CurrentField == "MAJOR_PROGRAM"){ <img src="../../Images/ico_tablesortoffset_desc.gif" alt = "table sort arrow desc"/>}           
        </th>
        <th>
            @Html.ActionLink("INVESTMENT AREA", "", new { sortOrder = ViewBag.currentOrder == "asc" ? "desc" : "asc", sortField = "INVESTMENT_AREA", Versions = ViewBag.SelectedVersion })
            @if (ViewBag.currentOrder == "asc" && ViewBag.CurrentField == "INVESTMENT_AREA"){ <img src="../../Images/ico_tablesortoffset_asc.gif" alt = "table sort arrow asc"/>}
            @if (ViewBag.currentOrder == "desc" && ViewBag.CurrentField == "INVESTMENT_AREA"){ <img src="../../Images/ico_tablesortoffset_desc.gif" alt = "table sort arrow desc" />}   
        </th>
        <th>
            @Html.ActionLink("Version", "", new { sortOrder = ViewBag.currentOrder == "asc" ? "desc" : "asc", sortField = "VERSION", Versions = ViewBag.SelectedVersion })
            @if (ViewBag.currentOrder == "asc" && ViewBag.CurrentField == "VERSION"){ <img src="../../Images/ico_tablesortoffset_asc.gif" alt = "table sort arrow asc" />}
            @if (ViewBag.currentOrder == "desc" && ViewBag.CurrentField == "VERSION"){ <img src="../../Images/ico_tablesortoffset_desc.gif" alt = "table sort arrow desc"/>}   
        </th>
        <th>
            @Html.ActionLink("VP", "", new { sortOrder = ViewBag.currentOrder == "asc" ? "desc" : "asc", sortField = "VP", Versions = ViewBag.SelectedVersion })
            @if (ViewBag.currentOrder == "asc" && ViewBag.CurrentField == "VP"){ <img src="../../Images/ico_tablesortoffset_asc.gif" alt = "table sort arrow asc"/>}
            @if (ViewBag.currentOrder == "desc" && ViewBag.CurrentField == "VP"){ <img src="../../Images/ico_tablesortoffset_desc.gif" alt = "table sort arrow desc"/>}   
        </th>
        <th>
            @Html.ActionLink("DIRECTOR", "", new { sortOrder = ViewBag.currentOrder == "asc" ? "desc" : "asc", sortField = "DIRECTOR", Versions = ViewBag.SelectedVersion })
            @if (ViewBag.currentOrder == "asc" && ViewBag.CurrentField == "DIRECTOR"){ <img src="../../Images/ico_tablesortoffset_asc.gif" alt = "table sort arrow asc"/>}
            @if (ViewBag.currentOrder == "desc" && ViewBag.CurrentField == "DIRECTOR"){ <img src="../../Images/ico_tablesortoffset_desc.gif" alt = "table sort arrow desc"/>}   
        </th>       
        <th></th>
    </tr>
@{
    var row_class = "odd";
}

@foreach (var item in Model) {
     row_class = row_class == "odd"? "even" : "odd";    
    <tr class="@row_class">
        <td>
            @Html.DisplayFor(modelItem => item.PA)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.MAJOR_PROGRAM)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.INVESTMENT_AREA)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.VERSION)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.VP)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.DIRECTOR)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.PA}) |

            @Html.ActionLink("Delete", "Delete", new { id = item.PA})
        </td>
    </tr>
}

</table>

<div>
    <div class="lefty">
    Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
    of @Model.PageCount
    &nbsp;&nbsp;&nbsp;&nbsp;
    @if (Model.HasPreviousPage)
    {
        @Html.ActionLink("<<", "", new { page = 1, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter, Versions = ViewBag.SelectedVersion })
        @Html.Raw(" ");
        @Html.ActionLink("< Prev", "", new { page = Model.PageNumber - 1, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter, Versions = ViewBag.SelectedVersion })
    }
    else
    {
        @:<<
        @Html.Raw(" ");
        @:< Prev
    }

    @if (Model.HasNextPage)
    {
        @Html.ActionLink("Next >", "", new { page = Model.PageNumber + 1, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter, Versions = ViewBag.SelectedVersion })
        @Html.Raw(" ");
        @Html.ActionLink(">>", "", new { page = Model.PageCount, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter, Versions = ViewBag.SelectedVersion })
    }
    else
    {
        @:Next >
        @Html.Raw(" ")
        @:>>
    }
    </div>
    <div class="righty">
    Showing Records @Model.FirstItemOnPage to @Model.LastItemOnPage from @Model.TotalItemCount
    </div>
</div>
<br /><br />
<div>
@Html.ActionLink("Download in Excel Format", "PaExcelOutput", new {Versions = ViewBag.SelectedVersion, currentFilter = ViewBag.currentFilter})
</div>
  • 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-03T12:55:05+00:00Added an answer on June 3, 2026 at 12:55 pm

    You could use Dynamic Query which allows you to use dynamic column names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to create a new google custom search engine, but when
I am trying to create a function that will split a string into search
I'm trying to create a simple search function where a user selects an option
I am trying to create a search page, this allows the admin to search
I am trying to create a jQuery click function that will close a div
I'm trying to create a function pointer that takes a function pointer as an
Ran into an issue today that I have not been able to resolve. I
I'm trying to create a function that goes to a specific directory, and if
I am trying to create a custom Binary Search Tree, and I have everything
So I'm trying to create a function in powershell that nests all the groups

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.