当前位置: 首页>>代码示例>>C#>>正文


C# TagHelperContext.SetChildrenReductionContext方法代码示例

本文整理汇总了C#中Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext.SetChildrenReductionContext方法的典型用法代码示例。如果您正苦于以下问题:C# TagHelperContext.SetChildrenReductionContext方法的具体用法?C# TagHelperContext.SetChildrenReductionContext怎么用?C# TagHelperContext.SetChildrenReductionContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext的用法示例。


在下文中一共展示了TagHelperContext.SetChildrenReductionContext方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessAsync

        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            //estabilish context
            if (For == null) throw new ArgumentNullException(ForAttributeName);
            if (RequiredFunctionalities == null)
            {
                if(Type == GridType.Immediate)
                    RequiredFunctionalities =  (x) => Functionalities.FullDetail;
                else
                    RequiredFunctionalities = (x) => Functionalities.FullInLine;
            }
            string fullName = ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(For.Name);
            string id = OverrideId ?? TagBuilder.CreateSanitizedId(fullName, IdAttributeDotReplacement);
            var currProvider = ViewContext.TagHelperProvider();
            var actTagName = TagName + (Type == GridType.Batch ? "-batch" : "-immediate");
            var defaultTemplates = currProvider.GetDefaultTemplates(actTagName);
            var ctx = new ContextualizedHelpers(ViewContext, html, httpAccessor, component, urlHelperFactory, factory);
            //

            //get row definitions
            IList<RowType> rows = string.IsNullOrEmpty(RowsCacheKey) ?
                null :
                RowType.GetRowsCollection(RowsCacheKey);
            var nc = new ReductionContext(TagTokens.RowContainer, 0,defaultTemplates, rows != null);
            context.SetChildrenReductionContext(nc);
            await output.GetChildContentAsync();
            var collector = new RowContainerCollector(nc);
            var res= collector.Process(this, defaultTemplates) as Tuple<IList<RowType>, IList<KeyValuePair<string, string>>>;
            if (rows == null)
            {
                rows = res.Item1;
                if (!string.IsNullOrEmpty(RowsCacheKey))
                    RowType.CacheRowGroup(RowsCacheKey, rows, httpAccessor.HttpContext);
                foreach(var row in rows)
                {
                    if(row.ControllerType != null)
                    {
                        Action action = () =>
                        {
                            ControllerHelpers.DeclareServerRowtype(row.ControllerType, row);
                        };
                        CacheViewPartsFilter.AddAction(httpAccessor.HttpContext, action);
                    }
                }
            }
            var toolbars = res.Item2;
            //

            //Prepare grid options
            var options = new GridOptions(rows, toolbars, Type, id, fullName)
            {
                CssClass=CssClass,
                ErrorMessages=ErrorMessages,
                ClientRowSelection=ClientRowSelection,
                ServerRowSelection=ServerRowSelection,
                LayoutTemplate=defaultTemplates.GetLayoutTemplate(LayoutTemplate),
                SubTemplates=defaultTemplates.GetLayoutParts(LayoutParts)
            };
            //finally process!
            await currProvider.GetTagProcessor(actTagName)(context, output, this, options, ctx);
        }
开发者ID:MvcControlsToolkit,项目名称:MvcControlsToolkit.ControlsCore,代码行数:61,代码来源:GridTagHelper.cs

示例2: ProcessAsync

        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            //estabilish context
            if (For == null) throw new ArgumentNullException(ForAttributeName);
            if (Mode != null && Mode.Metadata.UnderlyingOrModelType != typeof(bool))
                throw new ArgumentException(ModeName, string.Format(Resources.MustBeBool, ModeName));
            if (ModelNullRow != null && Mode.Metadata.UnderlyingOrModelType != typeof(int))
                throw new ArgumentException(ModelNullRowName, string.Format(Resources.MustBeInt, ModelNullRowName));
            string fullName = ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(For.Name);
            string id = OverrideId ?? TagBuilder.CreateSanitizedId(fullName, IdAttributeDotReplacement);
            var currProvider = ViewContext.TagHelperProvider();
            var defaultTemplates = currProvider.GetDefaultTemplates(TagName);
            var ctx = new Core.Templates.ContextualizedHelpers(ViewContext, html, httpAccessor, component, urlHelperFactory, factory);
            //

            //get row definitions
            IList<RowType> rows = string.IsNullOrEmpty(RowsCacheKey) ?
               null :
               RowType.GetRowsCollection(RowsCacheKey);
            var nc = new Core.OptionsParsing.ReductionContext(Core.OptionsParsing.TagTokens.RowContainer, 0, defaultTemplates, rows != null);
            context.SetChildrenReductionContext(nc);
            await output.GetChildContentAsync();
            var collector = new Core.OptionsParsing.RowContainerCollector(nc);
            var res = collector.Process(this, defaultTemplates) as Tuple<IList<Core.Templates.RowType>, IList<KeyValuePair<string, string>>>;
            if (rows == null)
            {
                rows = res.Item1;
                if (!string.IsNullOrEmpty(RowsCacheKey))
                    RowType.CacheRowGroup(RowsCacheKey, rows, httpAccessor.HttpContext);
            }
            var toolbars = res.Item2;
            //Prepare detail options
            var options = new Core.TagHelpers.Internals.GridOptions(rows, toolbars, GridType.Batch, id, fullName)
            {
                CssClass = CssClass,
                ErrorMessages = null,
                ClientRowSelection = ClientRowSelection,
                ServerRowSelection = ServerRowSelection,
                LayoutTemplate = defaultTemplates.GetLayoutTemplate(LayoutTemplate),
                SubTemplates = null
            };
            //finally process!
            await currProvider.GetTagProcessor(TagName)(context, output, this, options, ctx);
        }
开发者ID:MvcControlsToolkit,项目名称:MvcControlsToolkit.ControlsCore,代码行数:44,代码来源:DetailTagHelper.cs


注:本文中的Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext.SetChildrenReductionContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。