Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is how my search looks like in a Contoller

IEnumerable<view_service> schedule_name = db.Database.SqlQuery<models.view_service>(sql).ToList();


            // searching string filter
            if (current_filter == null || current_filter == "_")
                current_filter = "";

            ViewBag.current_filter = current_filter;

            // search string in schedule_name by bus_name and driver_name
            if (!String.IsNullOrEmpty(current_filter))
                schedule_name = schedule_name.Where
                    (s => s.code.ToUpper().Contains(current_filter.ToUpper()));

            
            //sorting order by code, name, insert_timestamp  

            ViewBag.code = sort_order == "code" ? "code_desc" : "code";
            ViewBag.name = sort_order == "name" ? "name_desc" : "name";
            ViewBag.insert_timestamp = sort_order == "insert_timestamp" ? "insert_timestamp_desc" : "insert_timestamp";

            ViewBag.current_sort = sort_order;
            switch (sort_order)....


The output is search box that searches code and it works fine. I also have dropdownlist that unfotunetly doesen't give back search results by name.
Code in view looks like this
<select data-placeholder="Choose schedule..." class="chosen-select-group" style="width: 260px;" tabindex="-1" value="@ViewBag.current_filter">
                                    --Choose schedule--
                                    @foreach (var item in ViewBag.schedules)
                                {
                                    if (item.id.ToString() == ViewBag.Schedule_id.ToString())
                                    {
                                        @item.name
                                    }
                                    else
                                    {
                                        @item.name
                                    }
                                }       
</select>



What should i ad to my search string that would filter name in dropdown?

What I have tried:

I have tried adding same search string that i have for code search. I tried List<>, Select List - maybe not correct.
Posted
Updated 17-Apr-18 1:18am
v2
Comments
j snooze 17-Apr-18 17:30pm    
are you missing the "option" tags in your Select? By the way there are html drop down helpers in MVC so you don't have to do a for each.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900