Click here to Skip to main content
15,944,837 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can you please anyone help me how to filter index by passing multiple parameters.
My model is
City which have CountryId and StateId So the user first select country and then state
and then enter name of city.
How can i do my code is given below.
Thank you
C#
public ActionResult Index(string searchString, string currentFilter, int? page, string sortOrder)
      {
          ViewBag.CurrentSort = sortOrder;
          ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";


          if (searchString != null)
          {
              page = 1;
          }
          else
          {
              searchString = currentFilter;
          }

          ViewBag.CurrentFilter = searchString;

          var result = from c in db.cities
                       select c;

          if (!String.IsNullOrEmpty(searchString))
          {

              result = result.Where(c => c.CityName.Contains(searchString));

          }
          result = result.OrderByDescending(x => x.CountryId);

          int pageSize = 6;
          int pageNumber = (page ?? 1);
          return View(result.ToPagedList(pageNumber, pageSize));
      }
Posted
Comments
Sinisa Hajnal 25-Jan-16 2:44am    
You already have multiple parameters...you just have to add additional parameters stateId and countryId. Or, if you're already passing them as currentFilter, you have to parse the variable into two separate ones.

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



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