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:
<a href="@Url.Action("Post", "Posts", new { id = item.PostId })#comments" ...></a>
# is for hash, so to send it server-side (which Url.Action is expecting) means encoding it. If you're looking to supplement the client experience, don't include it in your Url.Action (or create a special overload that accepts a fragment identifier and outputs it un-touched).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With