Custom TagHelper

1 Answer 405 Views
TextBox
NYO
Top achievements
Rank 2
Iron
NYO asked on 28 Jun 2021, 08:21 AM | edited on 28 Jun 2021, 08:22 AM

Hi am trying to add the kendo textbox in my custom Tag helper. I am not able to do it.

 

  public string Title { get; set; }
        public  override void Process(TagHelperContext context, TagHelperOutput output)
        {
            string htmlContent = $@"<div class=text-left>
                <div class=row col-12>
                    <div class=col-6>
                        <label >Name</label>
                    </div>
                    <div class=col-6>
             <kendo-textbox name=Name placeholder=Name ></kendo-textbox>
                  </div>
                </div>
                <div class=dropdown-divider></div>
            </div>";



            output.TagName = "div";
            output.Content.SetHtmlContent(htmlContent);
            output.TagMode = TagMode.StartTagAndEndTag;
        }

1 Answer, 1 is accepted

Sort by
0
Accepted
Tsvetomir
Telerik team
answered on 30 Jun 2021, 12:48 PM

Hi, NYO,

Speaking outside of the Telerik UI suite, the nesting of a TagHelper inside a TagHelper is not directly supported. However, it has its alternative and is outlined in the following StackOverflow thread:

https://stackoverflow.com/questions/42010429/can-i-use-a-tag-helper-in-a-custom-tag-helper-that-returns-html

Since the Telerik UI TextBox widget is relatively simple, you could directly configure the HTML of the input to match the Telerik UI TextBox. Namely:

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            string htmlContent = $@"<div class=text-left>
                <div class=row col-12>
                    <div class=col-6>
                        <label >Name</label>
                    </div>
                    <div class=col-6>
                    <input name=Name placeHolder=Name class='k-textbox' />
                  </div>
                </div>
                <div class=dropdown-divider></div>
            </div>";

            output.TagName = "div";
            output.Content.SetHtmlContent(htmlContent);
        }

I hope you find this helpful.

 

Kind regards,
Tsvetomir
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
TextBox
Asked by
NYO
Top achievements
Rank 2
Iron
Answers by
Tsvetomir
Telerik team
Share this question
or