Including hash values ​​in ASP.NET MVC URLs

I need to implement a hash value, i.e. Url should look like this:

/ home / index / # create

To do this, added the route:

routes.MapRoute( "Default", // Route name "{controller}/{action}/#{detail}", // URL with parameters new { controller = "Login", action = "LogIn", detail =""} // Parameter defaults ); 

When accessing /home/index/#create it redirects me to the default route.

How can I do that?

+45
asp.net-mvc routes
Apr 6 2018-11-11T00:
source share
3 answers

You cannot get the value after the # character on the server simply because this value is never sent to the server. Only client-side javascript has access to this, so defining routes with a hash doesn't make much sense.

+45
Apr 6 2018-11-11T00:
source share

As indicated, there is no way to do this using routing. The only possible solution is to add the # fragment to your URL when redirecting your controller actions. For example.

 return Redirect(Url.Action("Index", "Home") + "#create"); 
+92
Apr 6 2018-11-11T00:
source share

When the browser makes a request to the URL, it does not send anything after the hash to the server. This route may allow you to generate route URLs containing a hash value, but there is no way to do anything on the server side when the user navigates to that URL. This is how the website works ...

+4
Apr 6 2018-11-11T00:
source share



All Articles