Reputation: 2415
is it possible to retrieve action name from HttpContext.Request
which that request came.
I already know that I can get HttpContext.Request.UrlReferrer
but I want to know what was the previous action.
Upvotes: 0
Views: 99
Reputation: 17182
You have to use TempData or HiddenFields and store the previous Controller and Action. Request object doesn't hold anything (except UrlReferer) to keep track of old Action and Controller.
You can do some string manipulations on UrlReferer to parse it and get to know about previous controller action. But I am not going to suggest that way. Remember UrlReferer can easily manipulated.
Using TempData is one way for server to keep track of data for individual request. You can also use HiddenFields to store the same information. But that decision between TempData and HiddenFields is to be taken on the grounds of how secure and important that this (Previous controller and action) information is going to be for application.
Between you can get present Action and Controller values using -
ControllerContext.RouteData.Values["Controller"];
ControllerContext.RouteData.Values["Action"];
Upvotes: 1