Is it possible to extend WidgetBuilderBase?

4 posts, 2 answers
  1. Answer
    Ross B.
    Ross B. avatar
    21 posts
    Member since:
    Dec 2011

    Posted 26 Nov 2013 Link to this post

    Greetings,

    I would like to extend a Kendo.Mvc.UI.Fluent builder in my own html helper method and would like to know the easiest way to do this. To use a very simple scenario, I have many @Kendo.Button components that optionally need to be hidden. Until now I have created HtmlHelper functions and send in my custom parameters for various controls. I would like to start extending the WidgetBuilder itself.

    For example is something like this easy to accomplish:

    public class MyButtonBuilder : Kendo.Mvc.UI.Fluent.ButtonBuilder
    {
        public bool Visible { get; set; }
         
        public override void Render()
        {
            if(Visible==false)
                //Do something to return empty HTML
            else
                base.Render();
        }
    }



    Thanks
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 27 Nov 2013 Link to this post

    Hi Ross,

    You can try something like this:

    public class MyButtonBuilder : ButtonBuilder
    {
        public MyButtonBuilder(Button button) : base(button)
        {
        }
    }
     
    public static class MyExtensions
    {
        public static MyButtonBuilder MyButton(this HtmlHelper helper)
        {
            return new MyButtonBuilder(helper.Kendo().Button().ToComponent());
        }
    }


    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Ross B.
    Ross B. avatar
    21 posts
    Member since:
    Dec 2011

    Posted 27 Nov 2013 Link to this post

    Hi Atanas and thanks for the quick reply.

    I will use your examples to create widget's in the future. I am now struggling to find documentation or direction on which methods would need to be overridden to render the control as hidden or nothing. 

    .ToHtmlString()?


    In the snippet below
    @HtmlHelper.ExtendedKendoButton().Name("btnTest").Icon("cancel").Visible(false)

    What methods would I need to override to inspect a visible property and render HtmlRaw("") or some attribute that makes the markup invisible?


    Thanks again!
  5. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 27 Nov 2013 Link to this post

    Hi,

    It would have beenthe ToHtmlString method however it is not virtual. You can override Render though. Then you need to output your widget like this:

    @{ 
    Html.ExtendedKendoButton().Name("btnTest").Icon("cancel").Visible(false).Render();
    }

    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready