예제 #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;
        }