views:

156

answers:

4

I want to use a RedirectToRouteResult to redirect to a url like /users/4#Summary. Using ASP.NET MVC 1.0, I haven't been able to find a way to do that - have I missed it?

A: 

I do a something like that on my site here. But it's not with RedirectToRouteResult. RedirectToRouteResult does not support including an anchor part to the url.

You need to build the link yourself and perhaps even the logic to handle the processing of the anchor part - as i did. My application tries to replicate functionality similar to that of the Facebook photo gallery views. Each link to a different page must have a unique url, so for this i use the anchor part. But coz it does not translate direct to a route i have to parse the anchor part of the url manually on the page and use ajax to load in the appropriate content. This is what i wanted so it works for me.

cottsak
That's just it; I know I can build a URL myself, but I want to benefit from strongly-typed checks in my unit-tests when asserting, for example.
Peter Mounce
i see. well i think you're out of luck then
cottsak
A: 

Download the source code of MVC and check out how RedirectToRouteResult works

There may be better ways but a simple inheritance of RedirectToRouteResult and an override of ExecuteResult to allow an optional anchor part should fix the problem

TFD
+2  A: 

You should properly build your routes in route table. Eg.:

routes.MapRoute("MyRoute" ,"{controler}/{id}#{detail}" ,new { controller = "users", action = "index", id = (string)null, detail = "Summary" });
dario-g
A: 

I had a similar problem, take a look here:

http://stackoverflow.com/questions/2071414/linking-to-location-on-page-id-through-asp-net-mvc-mechanisms

I ended up creating a route using #.

Terje