Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including hash values in ASP.NET MVC URL routes

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

/home/index/#create

For this have added a route:

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

On accessing /home/index/#create, it is redirecting me to the default route.

How can this be done?

like image 532
facebook Avatar asked Apr 06 '11 14:04

facebook


3 Answers

As stated there is no way to do this using routing. The only possible solution is to append the # fragment to your url when redirecting in the actions of your controller. Eg.

return Redirect(Url.Action("Index", "Home") + "#create");
like image 68
Rory McCrossan Avatar answered Nov 20 '22 20:11

Rory McCrossan


You cannot fetch the value after the # symbol 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 hash doesn't make much sense.

like image 53
Darin Dimitrov Avatar answered Nov 20 '22 21:11

Darin Dimitrov


When a browser makes a request for a URL, it does not send anything after a hash to the server. This route may enable you to generate route URLs containing the hash value but there is no way to do anything server-side when the user navigates to such a URL. That's just the way the web works...

like image 7
Robert Levy Avatar answered Nov 20 '22 20:11

Robert Levy