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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:25:49+00:00 2026-05-30T10:25:49+00:00

I’m implementing a faceted search functionality where the user can filter and drill down

  • 0

I’m implementing a faceted search functionality where the user can filter and drill down on 4 properties of my model: City, Type, Purpose and Value.

I have a view section with the facets like this:

enter image description here

Each line displayed in the above image is clickable so that the user can drill down and do the filtering…

The way I’m doing it is with query strings that I pass using a custom ActionLink helper method:

 @Html.ActionLinkWithQueryString(linkText, "Filter",
                                 new { facet2 = Model.Types.Key, value2 = fv.Range });

This custom helper keeps the previous filters (query string parameters) and merges them with new route values present in other action links. I get a result like this when the user has applied 3 filters:

http://leniel-pc:8083/realty/filter?facet1=City&value1=Volta%20Redonda&
facet2=Type&value2=6&facet3=Purpose&value3=3

It’s working but I’d like to know about a better/cleaner way of doing this using routes. The order of the parameters can change depending on the filters the user has applied. I have something like this in mind:

http://leniel-pc:8083/realty/filter // returns ALL rows

http://leniel-pc:8083/realty/filter/city/rio-de-janeiro/type/6/value/50000-100000

http://leniel-pc:8083/realty/filter/city/volta-redonda/type/6/purpose/3

http://leniel-pc:8083/realty/filter/type/7/purpose/1

http://leniel-pc:8083/realty/filter/purpose/3/type/4

http://leniel-pc:8083/realty/filter/type/8/city/carangola

Is this possible? Any ideas?

  • 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-30T10:26:15+00:00Added an answer on May 30, 2026 at 10:26 am

    Is this possible? Any ideas?

    I would keep the query string parameters for filtering.

    But if you wanted to achieve the urls you have asked for in your question I will cover 2 possible techniques.

    For both approaches that I will present here I assume that you already have a view model:

    public class FilterViewModel
    {
        public string Key { get; set; }
        public string Value { get; set; }
    }
    

    and a controller:

    public class RealtyController : Controller
    {
        public ActionResult Filter(IEnumerable<FilterViewModel> filters)
        {
            ... do the filtering ...
        }
    }
    

    The first option is to write a custom model binder that will be associated with the IEnumerable<FilterViewModel> type:

    public class FilterViewModelBinder : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var filtersValue = bindingContext.ValueProvider.GetValue("pathInfo");
            if (filtersValue == null || string.IsNullOrEmpty(filtersValue.AttemptedValue))
            {
                return Enumerable.Empty<FilterViewModel>();
            }
    
            var filters = filtersValue.AttemptedValue;
            var tokens = filters.Split('/');
            if (tokens.Length % 2 != 0)
            {
                throw new Exception("Invalid filter format");
            }
    
            var result = new List<FilterViewModel>();
            for (int i = 0; i < tokens.Length - 1; i += 2)
            {
                var key = tokens[i];
                var value = tokens[i + 1];
                result.Add(new FilterViewModel
                {
                    Key = tokens[i],
                    Value = tokens[i + 1]
                });
            }
    
            return result;
        }
    }
    

    which will be registered in Application_Start:

    ModelBinders.Binders.Add(typeof(IEnumerable<FilterViewModel>), new FilterViewModelBinder());
    

    and you will also have a filter route:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
        routes.MapRoute(
            "Filter",
            "realty/filter/{*pathInfo}",
            new { controller = "Realty", action = "Filter" }
        );
    
        routes.MapRoute(
            "Default",
            "{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
    

    A second possibility is to write a custom route

    public class FilterRoute : Route
    {
        public FilterRoute()
            : base(
                "realty/filter/{*pathInfo}", 
                new RouteValueDictionary(new 
                { 
                    controller = "realty", action = "filter" 
                }), 
                new MvcRouteHandler()
            )
        {
        }
    
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            var rd = base.GetRouteData(httpContext);
            if (rd == null)
            {
                return null;
            }
    
            var filters = rd.Values["pathInfo"] as string;
            if (string.IsNullOrEmpty(filters))
            {
                return rd;
            }
    
            var tokens = filters.Split('/');
            if (tokens.Length % 2 != 0)
            {
                throw new Exception("Invalid filter format");
            }
    
            var index = 0;
            for (int i = 0; i < tokens.Length - 1; i += 2)
            {
                var key = tokens[i];
                var value = tokens[i + 1];
                rd.Values[string.Format("filters[{0}].key", index)] = key;
                rd.Values[string.Format("filters[{0}].value", index)] = value;
                index++;
            }
    
            return rd;
        }
    }
    

    which will be registered in your RegisterRoutes method:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
        routes.Add("Filter", new FilterRoute());
    
        routes.MapRoute(
            "Default",
            "{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.