2013-05-16 28 views
0

當我的網址我怎樣才能加 「#」 這是我html.ActionLink:使用html.ActionLink

@Html.ActionLink("Comment", "Comment", new { id = item.NewsId, title = item.Title + "#disqus_thread" }) 

它給了我以下網址:中

http://localhost:62394/Home/Comment/5008/Iran%20women%20barred%20from%20presidency%23disqus_thread 

代替"#"它產生"%23"

我怎樣才能確保它變成這樣:

'

http://localhost:62394/Home/Comment/5008/Iran%20women%20barred%20from%20presidency#disqus_thread 

任何形式的幫助都非常感謝!

+0

我該怎麼做同樣的事情在MVC控制器類當我激情RedirectToAction –

回答

1

試試這個: -

ActionLink的轉換爲字符串使用URLDecode並改變它呈現爲Html.Raw。

@Html.Raw(HttpUtility.UrlDecode(Html.ActionLink("Comment", "Comment" 
, new { id = 
item.NewsId, title = item.Title + "#disqus_thread" }).ToString())) 
0

你應該插入之前的URL解碼:

@HttpUtility.UrlDecode(Html.ActionLink("Comment", "Comment", new { id = item.NewsId, title = item.Title + "#disqus_thread" })) 
+0

嗯,它不工作我recieving 2個錯誤的最佳重載的方法匹配「System.Web.HttpUtility.UrlDecode(串) '有一些無效的論點。參數1:無法從'System.Web.Mvc.MvcHtmlString'轉換爲'string' – Obsivus

3

你應該使用Url.Action這樣的:

<a href="@Url.Action("Comment", new { id = item.NewsId, title = item.Title })#disqus_thread">Comment</a> 

我相信這是更簡單,更清潔,更安全

0

當我們通過在請求的URL的查詢字符串中的特殊字符,可能會造成誤差,除非它們被正確編碼。這些特殊字符可以通過使用字符的十六進制值而不是字符本身來處理。的

因此而不是使用

@Html.ActionLink("Comment", "Comment", new { id = item.NewsId, title = item.Title + "#disqus_thread" }) 

使用十六進制值%23

@Html.ActionLink("Comment", "Comment", new { id = item.NewsId, title = item.Title + "%23disqus_thread" }) 

我希望這可以幫助你..

0

我有同樣的問題但它在DevExpress Grid Link中。這是我能夠解決它的唯一方法。

@Html.ActionLink("Comment", "Comment", new { id = item.NewsId, title = item.Title + "#disqus_thread" }).ToString().Replace("%23", "#")