Exemplo n.º 1
0
        public override ActionResult Execute(Content currentNode, IDictionary <string, string> macroParams, MacroDefinition macro, ControllerContext currentControllerContext, IRoutableRequestContext routableRequestContext)
        {
            //If this partial view is part of a package it will be prefixed with the package (area) name.
            //if so, then we need to ensure that the view is rendered in the context of the area so the view is found
            //properly.
            var macroParts = macro.SelectedItem.Split('-');
            var areaName   = macroParts.Length > 1 ? macroParts[0] : "";

            var model = new PartialViewMacroModel(currentNode, new BendyObject(macroParams));

            var partialViewResult = new PartialViewResult()
            {
                //if someone has put '-' in the view name, then we need to include those too, we just delimit the area name and view name by the 'first' '-'
                //ViewName = macroParts.Length > 1
                //        ? string.Join("", macroParts.Where((x, i) => i != 0))
                //        : string.Join("", macroParts),
                ViewName = GetFullViewPath(macro, routableRequestContext),
                ViewData = new ViewDataDictionary(model),
                TempData = new TempDataDictionary(),
            };

            var partialViewControllerContext = currentControllerContext;

            if (!areaName.IsNullOrWhiteSpace())
            {
                //need create a new controller context with the area info
                var areaRouteData = currentControllerContext.RouteData.Clone();
                areaRouteData.DataTokens["area"] = areaName;
                partialViewControllerContext     = new ControllerContext(currentControllerContext.HttpContext, areaRouteData, currentControllerContext.Controller);
            }

            //wire up the view object/data
            partialViewControllerContext.EnsureViewObjectDataOnResult(partialViewResult);

            return(partialViewResult);
        }
        public override ActionResult Execute(Content currentNode, IDictionary<string, string> macroParams, MacroDefinition macro, ControllerContext currentControllerContext, IRoutableRequestContext routableRequestContext)
        {
            //If this partial view is part of a package it will be prefixed with the package (area) name.
            //if so, then we need to ensure that the view is rendered in the context of the area so the view is found
            //properly.
            var macroParts = macro.SelectedItem.Split('-');
            var areaName = macroParts.Length > 1 ? macroParts[0] : "";

            var model = new PartialViewMacroModel(currentNode, new BendyObject(macroParams));

            var partialViewResult = new PartialViewResult()
            {
                //if someone has put '-' in the view name, then we need to include those too, we just delimit the area name and view name by the 'first' '-'
                //ViewName = macroParts.Length > 1 
                //        ? string.Join("", macroParts.Where((x, i) => i != 0))
                //        : string.Join("", macroParts),
                ViewName = GetFullViewPath(macro, routableRequestContext),
                ViewData = new ViewDataDictionary(model),
                TempData = new TempDataDictionary(),
            };

            var partialViewControllerContext = currentControllerContext;

            if (!areaName.IsNullOrWhiteSpace())
            {
                //need create a new controller context with the area info
                var areaRouteData = currentControllerContext.RouteData.Clone();
                areaRouteData.DataTokens["area"] = areaName;
                partialViewControllerContext = new ControllerContext(currentControllerContext.HttpContext, areaRouteData, currentControllerContext.Controller);                  
            }

            //wire up the view object/data
            partialViewControllerContext.EnsureViewObjectDataOnResult(partialViewResult);  

            return partialViewResult;
        }
Exemplo n.º 3
0
 // Gets a macro parameter in a safe manner with fallback
 public static string GetMacroParam(PartialViewMacroModel model, string key, string fallback)
 {
     return(GetMacroParam(model, key, s => s, fallback));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Attempt to get a Macro parameter from a PartialViewMacroModel
 /// </summary>
 /// <param name="partialViewMacroModel"></param>
 /// <param name="parameterAlias"></param>
 /// <returns>Parameter value if available, the default value for the type otherwise.</returns>
 public static T GetParameterValue <T>(this PartialViewMacroModel partialViewMacroModel, string parameterAlias)
 {
     return(partialViewMacroModel.GetParameterValue(parameterAlias, default(T)));
 }