There's a lot of information for building Uris from Controller and Action names, but how can I do this the other way around?
Basically, all I'm trying to achieve is to get the Controller and Action names from the referring page (i.e. Request.UrlReferrer). Is there an easy way to achieve this?
I think this should do the trick:
My Visual Studio is currently down so I could not test it, but it should work as expected.
Here is a lightweight way to do this without creating response objects.
Uses this custom
HttpContextBase
classWhy would you need to construct ActionLink from a url ? The purpose of ActionLink is just the opposite to make a url from some data. So in your page just do:
To expand on gdoron's answer, the
Uri
class has methods for grabbing the left and right parts of the URL without having to do string parsing:@gordon's solution works, but you need to use
if you want to go to previous action
I don't believe there is any built-in way to retrieve the previous Controller/Action method call. What you could always do is wrap the controllers and action methods so that they are recorded in a persistent data store, and then when you require the last Controller/Action method, just retrieve it from the database (or whatever you so choose).