Thursday, 19 September 2013

How do I get ActionParameters in OnActionExecuted

How do I get ActionParameters in OnActionExecuted

I'm building an history of the action a user called. For this I need all
the parameters in the original querystring. This needs to be done in the
OnActionExecuted (After the action) because some description information
are stored in the filterAction.Result.Model.MyDescription.
On the ActionExecutedContext I do not have access to the ActionParameters
and the RoutesValues only contains action, controller, id and culture. It
doesn't contains any of the other parameters that was included in the
querystring.
How can I preserve the ActionParameters from the OnActionExecuting to the
OnActionExecuted?
Controller:
[ReportHistoryLink]
public ActionResult Index(int id, DateTime at, string by)
{
var model = new ReportModel();
model.ReportDescription = "Some logic get the ReportDescription";
return View("Index", model);
}
ActionFilter:
public class ReportHistoryLinkAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext
filterContext)
{
var model =
(IModelWithReportDescription)((ViewResult)filterContext.Result).Model;
var description = model.ReportDescription;
var boxedId = filterContext.RouteData.Values["id"];
var id = Convert.ToInt32(boxedId);
if (id != 0 && !string.IsNullOrWhiteSpace(targetDescription))
{
var link = new HistoryLink
{
Id = id,
Description = description,
Route = filterContext.RouteData.Values //This doesn't
contains the "at and by parameters"
};
}
}
}

No comments:

Post a Comment