2014-04-01 63 views
-5

當我點擊以下鏈接:顯示查詢字符串asp.net

<a href="default.aspx/video/?title=I am trying get the string"> hi</a> 

它作爲顯示:

http://example.com/default.aspx/title/?title=I%20am%20trying%20get%20the%20string 

但我希望它顯示像鏈接:

http://example.com/default.aspx/title/?title=I_am_trying_get_the_string 
+4

使用' %20'是空間的URL編碼版本。如果你想用下劃線替換它,那麼你需要在你的代碼中處理它。 – Romoku

+0

@Romoku你好,請你指導我如何做到這一點。 – rahlrokks

+0

'Request.QueryString [「title」]。替換(「_」,「」)' – Romoku

回答

1

您可以使用HttpServerUtility.UrlDecode()

Server.UrlDecode(Request.QueryString["title"]).Replace("_", " "); 
+0

我試過了,但它返回的是帶「 - 」符號的相同網址。 – rahlrokks

+0

@rahlrokks,更新了我的答案。立即檢查 –

+0

感謝它現在的作品。 – rahlrokks

0

您可以爲同時給予價值查詢字符串

<a href="default.aspx/video/?title=I_am_trying_get_the_string"> hi</a> 

得到的輸出使用與string.replace()期望的值

String value = Request.QueryString["title"].ToString(); 
String valu = value.Replace("_"," "); 

的細節refer here

+0

Thanks ------ but only half of the requirement is completed. I have more then 100's of similar links and I can't change them manually rahlrokks

+0

where you stuck please tell ? –

+0

than change them dynamically in code behind or you can replace %20 with space while getting the value of query string –