Is it possible to insert the '#' (hash) character in the MVC routes?

2

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!

    
asked by anonymous 09.08.2016 / 00:30

2 answers

2

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 same Action() , 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.

    
09.08.2016 / 23:13
3
  

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.

    
09.08.2016 / 20:44