Is it possible to insert the # (hash) character in the MVC routes? I'm developing an MVC application in which one of the specifications is the use of # in the MVC routes.
Is it possible to do this natively? Is there any way around this?
Thank you!
Is it possible to insert the # (hash) character in the MVC routes? I'm developing an MVC application in which one of the specifications is the use of # in the MVC routes.
Is it possible to do this natively? Is there any way around this?
Thank you!
As already mentioned, with routes it is not possible to do this.
One way to do this would be to change the return from Controller
to Redirect()
to the page you want.
Something like this:
return Redirect("/Home/Contact#contato");
Or this:
return Redirect(Url.Action("Contact", "Home") + "#contato");
Remembering this will only place "an anchor" at the end of the URL. I'm not sure what you want to do with it.
For more details, this question has more answers about what you asked.
Note: If you choose to use
Redirect()
, be careful. If the request for the sameAction()
, will cause an Infinite Loop .
If you want to do this in the client, you can customize HtmlHelper and create your own with the route desired.
Is it possible to do this natively? Is there any way around this?
No. #
is a symbol reserved for browsers to indicate anchors and can not be part of routes.
Since only the client has access to what comes after #
, it does not make much sense to define routes with it. It would only confuse the browser and JavaScript would not work right.