开发者

How to append parameter?

How can I get a string by appending parameter(s) 开发者_运维百科to Request.Url.Query?

Let say I have a parameter "value=100"

Request.Url.Query                            After Appending
""                                           "?value=100"
"?"                                          "?value=100"
"?page=15"                                   "?page=15&value=100"
"?page=15&sort=col"                          "?page=15&sort=col&value=100"


You cannot append parameters to the current query string. The querystring is readonly. Now if you want to manipulate querystrings in your application you could use the Url helpers to generate and manipulate urls.

You could also checkout the ParseQueryString method but this is rarely useful in an ASP.NET MVC application where you have routes and url helpers.

Sample usage:

string query = "?page=15&sort=col";
var values = HttpUtility.ParseQueryString(query);
values["value"] = "100";
query = values.ToString(); // page=15&sort=col&value=100
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜