How to update querystring in C#?

后端 未结 11 1260
野的像风
野的像风 2020-12-02 12:06

Somewhere in the url there is a &sortBy=6 . How do I update this to &sortBy=4 or &sortBy=2 on a button click? Do I need to write custom string functions to creat

11条回答
  •  一个人的身影
    2020-12-02 13:05

    SolrNet has some very helpful Url extension methods. http://code.google.com/p/solrnet/source/browse/trunk/SampleSolrApp/Helpers/UrlHelperExtensions.cs?r=512

        /// 
        /// Sets/changes an url's query string parameter.
        /// 
        /// 
        /// URL to process
        /// Query string parameter key to set/change
        /// Query string parameter value
        /// Resulting URL
        public static string SetParameter(this UrlHelper helper, string url, string key, string value) {
            return helper.SetParameters(url, new Dictionary {
                {key, value}
            });
        }
    

提交回复
热议问题