Getting a RequestContext outside of the Controllers and Views in MVC

Just a simple example of how to get the RequestContext when you are not in the context of a controller or a view.

        public static RequestContext GetRequestContext()
      {
           HttpContextBase context = new HttpContextWrapper(HttpContext.Current);
           return new RequestContext(context, RouteTable.Routes.GetRouteData(context));
      }

References:
http://stackoverflow.com/questions/1082748/generating-urls-form-mvc-routes-in-a-management-layer

Advertisements
Posted in Uncategorized. Tags: . 1 Comment »

One Response to “Getting a RequestContext outside of the Controllers and Views in MVC”


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: