Search code examples
asp.net-mvcasp.net-mvc-4razoractionlink

How can I add "#" in my url when using html.ActionLink


This is my html.ActionLink:

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

it gives me following url:

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

instead of "#" it generates "%23"

How can I make sure it becomes like this:

`

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

Any kind of help is appreciate alot!


Solution

  • Try this:-

    Convert ActionLink to string use URLDecode and change it to render it as Html.Raw.

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