Sdl.Web.Mvc/Controllers/BaseController.cs
/// <summary>
/// Enriches a given Entity Model using an appropriate (custom) Controller.
/// </summary>
/// <param name="entity">The Entity Model to enrich.</param>
/// <returns>The enriched Entity Model.</returns>
/// <remarks>
/// This method is different from <see cref="EnrichModel"/> in that it doesn't expect the current Controller to be able to enrich the Entity Model;
/// it creates a Controller associated with the Entity Model for that purpose.
/// It is used by <see cref="PageController.EnrichEmbeddedModels"/>.
/// </remarks>
Enriches a given Entity Model using an appropriate (custom) Controller.
Enriches a given Entity Model using an appropriate ( custom ) Controller .
protected EntityModel EnrichEntityModel(EntityModel entity)
        {
            if (entity == null || entity.MvcData == null || !IsCustomAction(entity.MvcData))
            {
                return entity;
            }
            MvcData mvcData = entity.MvcData;
            using (new Tracer(entity, mvcData))
            {
                string controllerName = mvcData.ControllerName ?? SiteConfiguration.GetEntityController();
                string controllerAreaName = mvcData.ControllerAreaName ?? SiteConfiguration.GetDefaultModuleName();
                RequestContext tempRequestContext = new RequestContext(HttpContext, new RouteData());
                tempRequestContext.RouteData.DataTokens["Area"] = controllerAreaName;
                tempRequestContext.RouteData.Values["controller"] = controllerName;
                tempRequestContext.RouteData.Values["area"] = controllerAreaName;
                BaseController entityController = (BaseController) ControllerBuilder.Current.GetControllerFactory().CreateController(tempRequestContext, controllerName);
                entityController.ControllerContext = new ControllerContext(HttpContext, tempRequestContext.RouteData, entityController);
                return (EntityModel) entityController.EnrichModel(entity);
            }
        }
protected EntityModel EnrichEntityModel ( EntityModel entity ) { if ( entity == null || entity . MvcData == null || ! IsCustomAction ( entity . MvcData ) ) { return entity ; } MvcData mvcData = entity . MvcData ; using ( new Tracer ( entity , mvcData ) ) { string controllerName = mvcData . ControllerName ?? SiteConfiguration . GetEntityController ( ) ; string controllerAreaName = mvcData . ControllerAreaName ?? SiteConfiguration . GetDefaultModuleName ( ) ; RequestContext tempRequestContext = new RequestContext ( HttpContext , new RouteData ( ) ) ; tempRequestContext . RouteData . DataTokens [ " " ] = controllerAreaName ; tempRequestContext . RouteData . Values [ " " ] = controllerName ; tempRequestContext . RouteData . Values [ " " ] = controllerAreaName ; BaseController entityController = ( BaseController ) ControllerBuilder . Current . GetControllerFactory ( ) . CreateController ( tempRequestContext , controllerName ) ; entityController . ControllerContext = new ControllerContext ( HttpContext , tempRequestContext . RouteData , entityController ) ; return ( EntityModel ) entityController . EnrichModel ( entity ) ; } }
Enriches a given Entity Model using an appropriate (custom) Controller.
Enriches a given Entity Model using an appropriate ( custom ) Controller .
// Note: Entity Controllers don't have to inherit from EntityController per se, but they must inherit from BaseController.
The enriched Entity Model.
The enriched Entity Model .
entity
EntityModel
The Entity Model to enrich.
The Entity Model to enrich .
remarks
This method is different from  in that it doesn't expect the current Controller to be able to enrich the Entity Model;
it creates a Controller associated with the Entity Model for that purpose.
It is used by .
This method is different from in that it doesn ' t expect the current Controller to be able to enrich the Entity Model ; it creates a Controller associated with the Entity Model for that purpose . It is used by .