locked
Custom filter not registering in RouteValueDictionary RRS feed

  • Question

  • User1098690930 posted

    I have created a custom filter on my dynamic data website which uses a custom expression in my QueryExtender to catch the IQueryable with the data and then filter it. This works fine but when I select a value in my custom filter it's not added to the routeValueDictionary that's used to build the Insert Action path. 

    protected override void OnPreRenderComplete(EventArgs e)
    {
          RouteValueDictionary routeValues = new RouteValueDictionary(GridView1.GetDefaultValues());
          InsertHyperLink.NavigateUrl = table.GetActionPath(PageAction.Insert, routeValues);
          base.OnPreRenderComplete(e);
    }

    If I change one of the automatically added DynamicFilters in the QueryableFilterRepeater then it does get added in the route values and it sends me to the filtered insert page. How can I add my custom filter values to the route values ? I can do a caveman workaround by just manually adding the filter values after the call to GetDefaultValues() but I think there should be a better way. 

    Wednesday, September 9, 2015 8:56 AM

Answers

  • User-330204900 posted

    Hi adriang133, the bottom line is if the filter you are adding is not an actual filter then the system has no way of finding out what you have filtered by. this is because when a filter is applied that is when it is added, so you could add a custom filter control and make it hide it's self and let it do the filtering, or you can modify the "OnPreRenderComplete" method and add it there :(

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 10, 2015 8:04 AM

All replies

  • User-271186128 posted

    Hi adriang133,

    The RouteValueDictionary represents a case-insensitive collection of key/value pairs. And the RouteValueDictionary Constructor (Object) initializes a new instance of the RouteValueDictionary class and adds values that are based on properties from the specified object. So, please check the filter values.

    You could use the following code to add value into RouteValueDictionary.

        var routeValues = new RouteValueDictionary();
        routeValues.Add("UserId", "5");

    Here are some relevant articles, please refer to them:

    https://msdn.microsoft.com/en-us/library/system.web.routing.routevaluedictionary(v=vs.110).aspx

    https://msdn.microsoft.com/en-us/library/cc680272(v=vs.110).aspx

    https://msdn.microsoft.com/en-us/library/dd493084(v=vs.118).aspx

    Best regards,
    Dillion

    Wednesday, September 9, 2015 11:05 PM
  • User1098690930 posted

    Hi Zhi,

    I know I can add the values like that but it's a kind of ugly workaround. The values for the dictionary are retrieved by calling 

    GridView1.GetDefaultValues()

    so Instead of me adding my filter values after that call I'd like it to happen before that call, so they're retrieved by calling that function and I don't have to change the code in all of my List.aspx pages. This would be a better and more elegant solution than simply adding them after the GetDefaultValues() because I have more List.aspx pages and I don't want to have to change my code in all of them. I hope you understand where I'm getting at.

    Adrian

    Thursday, September 10, 2015 2:56 AM
  • User-330204900 posted

    Hi adriang133, the bottom line is if the filter you are adding is not an actual filter then the system has no way of finding out what you have filtered by. this is because when a filter is applied that is when it is added, so you could add a custom filter control and make it hide it's self and let it do the filtering, or you can modify the "OnPreRenderComplete" method and add it there :(

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 10, 2015 8:04 AM
  • User1098690930 posted

    Thanks Steven! It turns out what I was trying to do (a filter whose value persists through pages that have foreign key filters referencing the same entity) can be achieved a lot easier and cleaner by just creating a custom filter control and a custom FilterFactory. I have now implemented it that way and everything works fine. 

    Thursday, September 10, 2015 8:37 AM
  • User-330204900 posted

    that is great news, I would have gotten to that eventually :D

    Thursday, September 10, 2015 8:51 AM