コード例 #1
0
        /// <summary>
        /// 获取聚合区块对应的 BinderController。加载模板的时候,检查是否已经自定义了模板。
        /// </summary>
        /// <param name="section"></param>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public static ISectionBinder GetBinder(ContentSection section, MvcContext ctx)
        {
            IContentSectionTemplateService TplService = ObjectContext.Create <IContentSectionTemplateService>(typeof(ContentSectionTemplateService));
            ContentSectionTemplate         template   = TplService.GetById(section.TemplateId);
            String         binderName = string.Format("wojilu.Web.Controller.Content.Binder.{0}BinderController", template.TemplateName);
            ControllerBase controller = ControllerFactory.FindController(binderName, ctx) as ControllerBase;

            if (controller == null)
            {
                throw new Exception("ISectionBinder not found:" + binderName);
            }

            String customTemplateStr = getCustomTemplateBody(section, ctx);

            // 自定义模板
            if (strUtil.HasText(customTemplateStr))
            {
                controller.viewContent(customTemplateStr);
                return(controller as ISectionBinder);
            }
            else
            {
                Template currentView = controller.utils.getTemplateByFileName(BinderUtils.GetBinderTemplatePath(template));
                controller.utils.setCurrentView(currentView);
                return(controller as ISectionBinder);
            }
        }