コード例 #1
0
        public void InvokeViewComponent(string componentName, object parameters, out string viewHtml, out object model, out string viewPath, bool onlyModel = false)
        {
            viewHtml = null;
            model    = null;
            viewPath = null;
            var component = _viewComponentSelector.SelectComponent(componentName);

            if (component == null)
            {
                return;
            }
            if (!onlyModel)
            {
                var componentPath = $"Components/{component.FullName}/Default";
                viewPath = _viewAccountant.GetThemeViewPath(componentPath);
                if (viewPath.IsNullEmptyOrWhiteSpace())
                {
                    return;
                }
                viewHtml = ReadFile.From(viewPath).Content;
            }
            var instance            = DependencyResolver.ResolveOptional(component.TypeInfo.AsType(), true);
            var viewComponentResult = (ViewViewComponentResult)component.MethodInfo.Invoke(instance, new[] { parameters });

            model = viewComponentResult.ViewData.Model;
        }
コード例 #2
0
        public string ReadTemplateFile(Context context, string templateName)
        {
            templateName = templateName.Trim('"');
            var viewPath = _viewAccountant.GetThemeViewPath(templateName);

            if (string.IsNullOrEmpty(viewPath))
            {
                throw new FileSystemException(
                          $"The template '{templateName}' was not found. The following locations were searched:<br/>{string.Join("<br/>", _viewAccountant.GetSearchLocations())}");
            }
            return(_viewAccountant.RenderView(viewPath, templateName, null, context.Scopes[0]));
        }