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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:55:51+00:00 2026-05-27T20:55:51+00:00

I have an ASP.NET MVC website. In my backend I have a table called

  • 0

I have an ASP.NET MVC website. In my backend I have a table called People with the following columns:

  1. ID
  2. Name
  3. Age
  4. Location
  5. … (a number of other cols)

I have a generic web page that uses model binding to query this data. Here is my controller action:

public ActionResult GetData(FilterParams filterParams)
{
      return View(_dataAccess.Retrieve(filterParams.Name, filterParams.Age, filterParams.location, . . .)
}

which maps onto something like this:

 http://www.mysite.com/MyController/GetData?Name=Bill .. . 

The dataAccess layer simply checks each parameter to see if its populated to add to the db where clause. This works great.

I now want to be able to store a user’s filtered queries and I am trying to figure out the best way to store a specific filter. As some of the filters only have one param in the queryString while others have 10+ fields in the filter I can’t figure out the most elegant way to storing this query “filter info” into my database.

Options I can think of are:

  1. Have a complete replicate of the table (with some extra cols) but call it PeopleFilterQueries and populate in each record a FilterName and put the value of the filter in each of field (Name, etc)

  2. Store a table with just FilterName and a string where I store the actual querystring Name=Bill&Location=NewYork. This way I won’t have to keep adding new columns if the filters change or grow.

What is the best practice for this situation?

  • 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-27T20:55:51+00:00Added an answer on May 27, 2026 at 8:55 pm

    If the purpose is to save a list of recently used filters, I would serialise the complete FilterParams object into an XML field/column after the model binding has occurred. By saving it into a XML field you’re also giving yourself the flexibility to use XQuery and DML should the need arise at a later date for more performance focused querying of the information.

        public ActionResult GetData(FilterParams filterParams)
        {
              // Peform action to get the information from your data access layer here
              var someData = _dataAccess.Retrieve(filterParams.Name, filterParams.Age, filterParams.location, . . .);
    
              // Save the search that was used to retrieve later here
              _dataAccess.SaveFilter(filterParams);
              return View(someData);
        }
    

    And then in your DataAccess Class you’ll want to have two Methods, one for saving and one for retrieving the filters:

    public void SaveFilter(FilterParams filterParams){
        var ser = new System.Xml.Serialization.XmlSerializer(typeof(FilterParams));
        using (var stream = new StringWriter())
               {
                  // serialise to the stream
                  ser.Serialize(stream, filterParams);
               }
      //Add new database entry here, with a serialised string created from the FilterParams obj
      someDBClass.SaveFilterToDB(stream.ToString());
    }
    

    Then when you want to retrieve a saved filter, perhaps by Id:

    public FilterParams GetFilter(int filterId){
    
          //Get the XML blob from your database as a string
          string filter = someDBClass.GetFilterAsString(filterId);
    
          var ser = new System.Xml.Serialization.XmlSerializer(typeof(FilterParams));
    
          using (var sr = new StringReader(filterParams))
          {
              return (FilterParams)ser.Deserialize(sr);
          }
    }
    

    Remember that your FilterParams class must have a default (i.e. parameterless) constructor, and you can use the [XmlIgnore] attribute to prevent properties from being serialised into the database should you wish.

    public class FilterParams{
       public string Name {get;set;}
       public string Age {get;set;}
    
       [XmlIgnore]
       public string PropertyYouDontWantToSerialise {get;set;}
    }
    

    Note: The SaveFilter returns Void and there is no error handling for brevity.

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

Sidebar

Related Questions

i have an asp.net mvc website with a SQL server backend. For every table
I have the following view definition in my asp.net mvc website: <% Using Ajax.BeginForm(UsrCtlChangePassword,
i have a asp.net mvc website which runs a number of queries for each
I have an existing complex website built using ASP.NET MVC, including a database backend,
I have an asp.net-mvc website and people manage a list of projects. Based on
I have a asp.net-mvc website with a SQL server backend (using nhibernate for OR
I have an ASP.NET MVC website and an area project called 'Admin'. So far
So I have an ASP.NET MVC 3 website that allows people to advertise certain
i have a asp.net mvc website and the volume of traffic is increasing. I
I have an ASP.NET MVC website that works in tandem with a Windows Service

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.