Exemple #1
0
        //public override void Process(TagHelperContext context, TagHelperOutput output)
        //{
        //    base.Process(context, output);
        //}

        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            TagHelperUtil.CreateOrMergeAttribute("class", "form-control form-control-sm", output);
            output.TagName = "select";
            output.TagMode = TagMode.StartTagAndEndTag;

            TagHelperAttribute aspItemsAttribute = context.AllAttributes["asp-items"];
            object             aspItems          = aspItemsAttribute.Value;
            object             newValue          = null;

            if (aspItems is IEnumerable <CodeNameModel> )
            {
                newValue = new Microsoft.AspNetCore.Mvc.Rendering.SelectList((IEnumerable <CodeNameModel>)aspItems, "Code", "Name");
            }
            else if (aspItems is IEnumerable <IdNameModel> )
            {
                newValue = new Microsoft.AspNetCore.Mvc.Rendering.SelectList((IEnumerable <IdNameModel>)aspItems, "Id", "Name");
            }

            if (newValue != null)
            {
                base.Items = (Microsoft.AspNetCore.Mvc.Rendering.SelectList)newValue;
            }
            else
            {
                base.Items = (Microsoft.AspNetCore.Mvc.Rendering.SelectList)aspItems;
            }
            await base.ProcessAsync(context, output);
        }
Exemple #2
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            TagHelperUtil.CreateOrMergeAttribute("class", "form-control form-control-sm", output);

            TagBuilder validationSpan = Generator.GenerateValidationMessage(ViewContext, For.ModelExplorer, For.Name, null,
                                                                            /*"small" - алтернатива на слагането на класове*/ null, new { @class = "col-form-label col-form-label-sm" });

            output.PostElement.AppendHtml(validationSpan.TagBuilderToString());

            if (((Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata)For.Metadata).Attributes.Attributes.
                Where(a => a is DataTypeAttribute && ((DataTypeAttribute)a).DataType == DataType.MultilineText).Any())
            {
                output.TagName = "textarea";
                output.TagMode = TagMode.StartTagAndEndTag;

                output.Content.SetHtmlContent(For?.Model?.ToString());
                base.Process(context, output);
                output.Attributes.Remove(output.Attributes["value"]);
            }
            else if (For.Metadata.ModelType == typeof(bool))
            {
                TagHelperUtil.CreateOrMergeAttribute("class", "form-control-checkbox-sm", output);
                base.Process(context, output);
            }
            else
            {
                output.TagName = "input";
                base.Process(context, output);
            }
        }
Exemple #3
0
 public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
 {
     TagHelperUtil.CreateOrMergeAttribute("class", "col-form-label col-form-label-sm", output);
     //output.Attributes.Add("class", "control-label");
     //output.Attributes.Add("asp-for", output.Attributes["asp-for2"].Value);
     output.TagName = "label";
     output.TagMode = TagMode.StartTagAndEndTag;
     if (For != null)
     {
         await base.ProcessAsync(context, output);
     }
 }
Exemple #4
0
 public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
 {
     TagHelperUtil.CreateOrMergeAttribute("class", "btn btn-sm", output);
     if (context.AllAttributes["href"] != null || context.AllAttributes["asp-action"] != null)
     {
         output.TagName = "a";
         await base.ProcessAsync(context, output);
     }
     else
     {
         output.TagName = "button";
     }
 }
Exemple #5
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (context.AllAttributes["asp-for"] == null)
            {
                output.TagName = "input";
                output.TagMode = TagMode.SelfClosing;

                var typeAttribute = context.AllAttributes["type"];
                if (typeAttribute != null && (typeAttribute.Value.ToString() == "submit" || typeAttribute.Value.ToString() == "button"))
                {
                    var valueAttribute = context.AllAttributes["value"];
                    TagHelperUtil.CreateOrMergeAttribute("value", valueAttribute.Value, output);
                    TagHelperUtil.CreateOrMergeAttribute("type", typeAttribute.Value, output);

                    TagHelperUtil.CreateOrMergeAttribute("class", "btn btn-sm btn-default", output);
                }
                else
                {
                    TagHelperUtil.CreateOrMergeAttribute("class", "form-control form-control-sm", output);
                    base.Process(context, output);
                }
            }
        }