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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:05:04+00:00 2026-05-24T03:05:04+00:00

How do I serialize an object into query-string format? I can’t seem to find

  • 0

How do I serialize an object into query-string format? I can’t seem to find an answer on google. Thanks.

Here is the object I will serialize as an example.

public class EditListItemActionModel
{
    public int? Id { get; set; }
    public int State { get; set; }
    public string Prefix { get; set; }
    public string Index { get; set; }
    public int? ParentID { get; set; }
}
  • 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-24T03:05:05+00:00Added an answer on May 24, 2026 at 3:05 am

    I’m 99% sure there’s no built-in utility method for this. It’s not a very common task, since a web server doesn’t typically respond with a URLEncoded key/value string.

    How do you feel about mixing reflection and LINQ? This works:

    var foo = new EditListItemActionModel() {
      Id = 1,
      State = 26,
      Prefix = "f",
      Index = "oo",
      ParentID = null
    };
    
    var properties = from p in foo.GetType().GetProperties()
                     where p.GetValue(foo, null) != null
                     select p.Name + "=" + HttpUtility.UrlEncode(p.GetValue(foo, null).ToString());
    
    // queryString will be set to "Id=1&State=26&Prefix=f&Index=oo"                  
    string queryString = String.Join("&", properties.ToArray());
    

    Update:

    To write a method that returns the QueryString representation of any 1-deep object, you could do this:

    public string GetQueryString(object obj) {
      var properties = from p in obj.GetType().GetProperties()
                       where p.GetValue(obj, null) != null
                       select p.Name + "=" + HttpUtility.UrlEncode(p.GetValue(obj, null).ToString());
    
      return String.Join("&", properties.ToArray());
    }
    
    // Usage:
    string queryString = GetQueryString(foo);
    

    You could also make it an extension method without much additional work

    public static class ExtensionMethods {
      public static string GetQueryString(this object obj) {
        var properties = from p in obj.GetType().GetProperties()
                         where p.GetValue(obj, null) != null
                         select p.Name + "=" + HttpUtility.UrlEncode(p.GetValue(obj, null).ToString());
    
        return String.Join("&", properties.ToArray());
      }
    }
    
    // Usage:
    string queryString = foo.GetQueryString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would it be possible to serialize a model object into a query string? I've
Is it possible to serialize an object into a string or a byte array
How can I serialize a .net object into XML and then de-serialize it back?
I want to serialize an object into an xml and I want the filename
I am able to serialize an object into a file and then restore it
Basically, I have a class with 2 methods: one to serialize an object into
I've run into some problems when trying to serialize my object to XML. The
I have an XML file that I'm trying to serialize into an object. Some
I need to serialize/de-serialize some objects into/from string and transfer them as just opaque
I can serialize an object to a file using: var writeStream = File.Open(l.osl, FileMode.Create);

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.