コード例 #1
0
        /// <inheritdoc />
        /// <remarks>Does nothing if <see cref="For"/> is <c>null</c>.</remarks>
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            IPlatformServices platFormServices = ViewContext.ViewBag.PlatFormServices;

            List <SelectListItem> selectItems = null;

            if (!string.IsNullOrEmpty(CodeList))
            {
                selectItems = platFormServices.GetPresentationCodelist(CodeList, TextName, ValueName);
            }

            // Ensure GenerateSelect() _never_ looks anything up in ViewData.
            var items = Enumerable.Empty <SelectListItem>();

            if (selectItems != null && selectItems.Count > 0)
            {
                items = selectItems;
            }

            if (For == null)
            {
                var options = Generator.GenerateGroupsAndOptions(optionLabel: null, selectList: items);
                output.PostContent.AppendHtml(options);
                return;
            }

            var tagBuilder = Generator.GenerateSelect(
                ViewContext,
                For.ModelExplorer,
                optionLabel: null,
                expression: For.Name,
                selectList: items,
                currentValues: _currentValues,
                allowMultiple: _allowMultiple,
                htmlAttributes: null);

            if (tagBuilder != null)
            {
                output.MergeAttributes(tagBuilder);
                output.PostContent.AppendHtml(tagBuilder.InnerHtml);
            }
        }