How to update querystring in C#?

后端 未结 11 1264
野的像风
野的像风 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 12:49

        private void UpdateQueryString(string queryString, string value)
        {
            PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
            isreadonly.SetValue(this.Request.QueryString, false, null);
            this.Request.QueryString.Set(queryString, value);
            isreadonly.SetValue(this.Request.QueryString, true, null);
        }
    

提交回复
热议问题