Including hash values in ASP.NET MVC URL routes

facebook picture facebook · Apr 6, 2011 · Viewed 34.7k times · Source

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?

Answer

Rory McCrossan picture Rory McCrossan · Apr 6, 2011

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");