From some of the action methods I want to return a result that will force current page to refresh.
I wrote this to acquire such result:
public class RefreshResult : ActionResult {
public override void ExecuteResult(ControllerContext context) {
Uri referrer = context.HttpContext.Request.UrlReferrer;
if(referrer == null || string.IsNullOrEmpty(referrer.AbsoluteUri)) {
return;
}
context.HttpContext.Response.Redirect(referrer.AbsoluteUri);
}
}
In my action methods I simply return new RefreshResult. It works, but I am curious of the possible limitations of such approach. I am not intrested in giving customers an option to access action methods returning such results directly, so I think that I always will be able to refresh current page in such a way. Am I right?
I found this (and couple of other questions) on stackoverflow: ActionResult return to page that called it
But I am more intrested in possible limitations of such approach, not in a "how to".
Thanx in advance
rouen answer is one way to refresh the page. The other one is to redirect back to the Url that the request was sent from, and there is no need to write implementation yourself, just do it in a normal action in a controller.
The Action might look like this
public ActionResult SomeAction()
{
//do some work here...
return Redirect(Request.UrlReferrer.ToString());
}