• Code
  • Tags
  • Users
  • Titles
  • Log in
  • Feedback
  • FAQ
Share Code
Welcome to ForkCan.com

ForkCan is all about sharing code in a social way.

Discuss, debate or argue with other devs about their or your own code.

Give other devs feedback or make a Fork (Make a better version of a shared code).

Rate the code, if you use the code mark it as used so others can see if the shared code is used by someone.

Help each other to be better devs and to be more productive.


Features not working yet:

Flag a post


QR Code

Tiny Url

https://www.4kcan.com/s/NjA1

Related Code
Fork of Serialize an object into a Querystring, using LINQ syntax
Using DynamicObject to get a value from the Request.Params
Fork of GZIP your Actions in MVC if not used as standard in IIS7 or only use IIS6
A simple way to cache slow functions in C#
ActionFilter to Handle and Log Error for each Controller, ASP.NET MVC
Serialize (anonymous) objects to xml
Get Cookies in Web Api Asp .net Mvc 4 RC
GZIP your Actions in MVC if not used as standard in IIS7 or only use IIS6

Serialize an object into a Querystring

Can be used to serialize an object to a QueryString.

0
3.27k 0 0 0 0 0

public static class HtmlHelper
{
    public static string SerializeToQueryString(object source)
    {
        if (source == null)
            throw new ArgumentNullException("source");

        var type = source.GetType();

        var queryString = new StringBuilder();

        foreach (var property in type.GetProperties())
        {
            var propertyValue = property.GetValue(source, new object[] {});

            if (propertyValue == null)
                continue;

            queryString.Append(HttpUtility.UrlEncode(property.Name));
            queryString.Append("=");
            queryString.Append(HttpUtility.UrlEncode(propertyValue.ToString()));
            queryString.Append("&");
        }

        if (queryString.Length > 0)
            queryString.Remove(queryString.Length - 1, 1);

        return queryString.ToString();
    }
}

/invoice/search/?" + HtmlHelper.SerializeToQueryString(searchInput)


Share: twitter | facebook   Action: used | fork | flag

asp.net

Mark 'asp.net' tag as 'like'

Mark 'asp.net' tag as 'ignore'

c#

Mark 'c#' tag as 'like'

Mark 'c#' tag as 'ignore'

html

Mark 'html' tag as 'like'

Mark 'html' tag as 'ignore'

serialize

Mark 'serialize' tag as 'like'

Mark 'serialize' tag as 'ignore'


 @fredrikn "I'm the master"
3.11k
February 16, 2011 3:07 PM

Fork

 Serialize an object into a Querystring -  @fredrikn Wednesday 16, 2011 3:07 PM
 Fork of Serialize an object into a Querystring, using LINQ syntax -  @benlaan Thursday 17, 2011 6:03 AM


0 Feedback


You must log in before you can give any feedback


0 Discussion(s)

Newest Oldest

You must log in before you can post a comment

Squeed
Made by: Fredrik Normén 2010