Пример #1
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "table";
            output.Attributes.Add("id", Id); //need to pass "id" through

            Options.Columns = Options.Columns ?? new DataTableOptionsColumn[0];
            var dataTableContext = new DataTableContext
            {
                Options = Options,
            };

            context.Items[typeof(DataTableContext)] = dataTableContext;

            await output.GetChildContentAsync();

            var json = JsonConvert.SerializeObject(
                Options,
                new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                Formatting        = Formatting.Indented,
                ContractResolver  = new CamelCasePropertyNamesContractResolver()
            });

            //Since the layout is executed after the view; init the BodyTagContext if none existent
            if (!ViewContext.ViewData.TryGetValue(nameof(BodyTagContext), out object bodyTagContext))
            {
                bodyTagContext = ViewContext.ViewData[nameof(BodyTagContext)] = new BodyTagContext();
            }

            ((BodyTagContext)bodyTagContext).Scripts.Add(String.Format(DATA_TABLE_SCRIPT_TEMPLATE, Id, json));
        }