2014-04-01 64 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 –