I want to have a url link like: /Posts/Post/1#comments
Where: Posts - controller name, Post - action name, 1 - id parameter
I am using following code in my View:
<a href="@Url.Action("Post", "Posts", new { id = @item.PostId + "#comments" })">Comments</a>
As a result I have: /Posts/Post/1%23comments
What to do to pass '#' char instead of "%23"?
you're looking for:
#
is for hash, so to send it server-side (whichUrl.Action
is expecting) means encoding it. If you're looking to supplement the client experience, don't include it in yourUrl.Action
(or create a special overload that accepts a fragment identifier and outputs it un-touched).