Replace item in querystring

前端 未结 11 1562
甜味超标
甜味超标 2020-12-11 01:23

I have a URL that also might have a query string part, the query string might be empty or have multiple items.

I want to replace one of the items in the query string

11条回答
  •  没有蜡笔的小新
    2020-12-11 01:34

    string link = page.Request.Url.ToString();
    
    if(page.Request.Url.Query == "")
        link  += "?pageIndex=" + pageIndex;
    else if (page.Request.QueryString["pageIndex"] != "")
    {
        var idx = page.Request.QueryString["pageIndex"];
        link = link.Replace("pageIndex=" + idx, "pageIndex=" + pageIndex);
    }
    else 
        link += "&pageIndex=" + pageIndex;
    

    This seems to work really well.

提交回复
热议问题