2009-03-02 28 views
77

tengo el siguiente problema: Por ejemplo tengo ruta así:ASP.Net MVC RedirectToAction con el ancla

routes.Add(new Route("forums/thread/{threadOid}/last", new MvcRouteHandler()) 
      Defaults = new RouteValueDictionary(
      new { controller = "Thread", action ="ShowThreadLastPostPage"}), 
     Constraints = new RouteValueDictionary(new { threadOid = @"^\d+$" }) 
    } 
); 

¿Hay alguna manera con el método RedirectToAction vaya a la dirección URL de esta manera:

forums/thread/{threadOid}/last#postOid

Respuesta

141

creo que debe utilizar el método Redirect junto con Url.RouteUrl para lograrlo.

return Redirect(Url.RouteUrl(new { controller = "Thread", action = "ShowThreadLastPostPage", threadOid = threadId }) + "#" + postOid); 
+0

Muchas gracias, ayuda! – inikulin

+3

¡Muchas gracias por la respuesta, me he estado preguntando esto por un tiempo! – thebrokencube

+0

Heh ... he estado tratando de resolver esto ... se me olvidó que el # thingy era un ancla. ¡Gracias por la publicacion! –

14

Otra alternativa con Url.Action:

return Redirect(Url.Action("ShowThreadLastPostPage", "Thread", new { threadOid = threadOid }) + "last#" + postOid); 
Cuestiones relacionadas