MVC3 integrated, with some changes to make it compile on Mono and with Razor2
[mono-project.git] / mcs / class / System.Web.Mvc3 / Mvc / RedirectToRouteResult.cs
blobd45b634c6309bedb3d5631e145b5929c4a6ccf5f
1 namespace System.Web.Mvc {
2 using System;
3 using System.Web.Mvc.Resources;
4 using System.Web.Routing;
6 // represents a result that performs a redirection given some values dictionary
7 public class RedirectToRouteResult : ActionResult {
9 private RouteCollection _routes;
11 public RedirectToRouteResult(RouteValueDictionary routeValues) :
12 this(null, routeValues) {
15 public RedirectToRouteResult(string routeName, RouteValueDictionary routeValues)
16 : this(routeName, routeValues, permanent: false) {
19 public RedirectToRouteResult(string routeName, RouteValueDictionary routeValues, bool permanent) {
20 Permanent = permanent;
21 RouteName = routeName ?? String.Empty;
22 RouteValues = routeValues ?? new RouteValueDictionary();
25 public bool Permanent {
26 get;
27 private set;
30 public string RouteName {
31 get;
32 private set;
35 public RouteValueDictionary RouteValues {
36 get;
37 private set;
40 internal RouteCollection Routes {
41 get {
42 if (_routes == null) {
43 _routes = RouteTable.Routes;
45 return _routes;
47 set {
48 _routes = value;
52 public override void ExecuteResult(ControllerContext context) {
53 if (context == null) {
54 throw new ArgumentNullException("context");
56 if (context.IsChildAction) {
57 throw new InvalidOperationException(MvcResources.RedirectAction_CannotRedirectInChildAction);
60 string destinationUrl = UrlHelper.GenerateUrl(RouteName, null /* actionName */, null /* controllerName */, RouteValues, Routes, context.RequestContext, false /* includeImplicitMvcValues */);
61 if (String.IsNullOrEmpty(destinationUrl)) {
62 throw new InvalidOperationException(MvcResources.Common_NoRouteMatched);
65 context.Controller.TempData.Keep();
67 if (Permanent) {
68 context.HttpContext.Response.RedirectPermanent(destinationUrl, endResponse: false);
70 else {
71 context.HttpContext.Response.Redirect(destinationUrl, endResponse: false);