title: Single Controller with Multiple Views
body: <p>I am trying to create an MVC application with multiple view, but using a single controller.  I started by creating a second route with another property that I could use to redirect to a second folder.</p>
  
  <pre><code>        public static void RegisterRoutes(RouteCollection routes)
      {
          routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
          routes.MapRoute(
              "xml",                                              // Route name
              "xml/{controller}/{action}/{id}",                           // URL with parameters
              new { mode = "xml", controller = "Home", action = "Index", id = "" }  // Parameter defaults
          );
  
          routes.MapRoute(
              "Default",                                              // Route name
              "{controller}/{action}/{id}",                           // URL with parameters
              new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
          );
      }
      protected void Application_Start()
      {
          RegisterRoutes(RouteTable.Routes);
          SessionManager.Instance.InitSessionFactory("acstech.helpWanted");
          ViewEngines.Engines.Clear();
          ViewEngines.Engines.Add(new ModeViewEngine()); 
      }
  </code></pre>
  
  <p>I followed that by descending from WebFormViewEngine and changed the path from ~/View to ~/{mode}View.  This worked and ran rendered the pages properly.  The problem that I ran into is that the Html.ActionLink always uses the mode version no matter what the view rendered.  Is this the proper direction for accomplishing my goal, if so what am I missing to get the Action Link to work properly.  Below is the ViewEngine.  This is a lab test, so some liberties have been taken.</p>
  
  <pre><code>public class ModeViewEngine : WebFormViewEngine
  {
      public ModeViewEngine()
      {
  
      }
  
      protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
      {
          string mode = String.Empty;
          if (controllerContext.RouteData.Values["mode"] != null)
              mode = controllerContext.RouteData.Values["mode"] as string;
          return new WebFormView(partialPath.Replace("~/Views", "~/" + mode + "Views"), null);
      }
  
      protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
      {
          string mode = String.Empty;
          if (controllerContext.RouteData.Values["mode"] != null)
              mode = controllerContext.RouteData.Values["mode"] as string;
          return new WebFormView(viewPath.Replace("~/Views", "~/" + mode + "Views"), masterPath);
      }
  }
  </code></pre>