Dynamically add controls to page

3 posts, 0 answers
  1. Tom
    Tom avatar
    12 posts
    Member since:
    May 2013

    Posted 05 May 2017 Link to this post

    I'm using the UI for MVC Core (Core 1.1). I need to allow users to build their own input forms (unlimited number of inputs and forms). I am storing the configuration of the form (e.g. settings for combobox, dateinput, textbox, etc.) in a database. I want to create the necessary mvc wrappers and save them to a file (or db)...i.e. cache the form. That way when the form is requested, I can just load the cached form. Here is an example of what I would store in a file or database.



    Is it possible to then load this information from database or file and have it parsed on a page (i.e. generate the kendo controls)?Or do the wrappers have to be added to the page at design time? If possible, how would I load the file?

    Or do I need to create the Kendo html elements instead like below? Or is there another option?

    <input id="currency" type="number" />
    <input id="currency2" type="number" value="50" />
      $(document).ready(function() {
        $("#currency").kendoNumericTextBox({format: "c"});
        $("#currency2").kendoNumericTextBox({format: "c"});


  2. Tom
    Tom avatar
    12 posts
    Member since:
    May 2013

    Posted 05 May 2017 in reply to Tom Link to this post

    One more thing...is it possible to generate the kendo controls from the controller? So in stead of adding the wrappers on the view using @(Html.Kendo()...),build the controls server side and then have them render in the view?
  3. Ianko
    Ianko avatar
    1956 posts

    Posted 10 May 2017 Link to this post

    Hello Tom,

    The closest built-in feature that you can use is the Kendo Binder.  http://docs.telerik.com/kendo-ui/api/javascript/data/binder. With it, you can use metadata stored in database and generate HTML tags with attributes to create form fields on the fly. 

    With Razor syntax, you can do the same by using the EditorFor and associate the Model classes by using the UIHint decorator. How this would go dynamic, however, I am not sure. http://www.growingwiththeweb.com/2012/12/aspnet-mvc-display-and-editor-templates.html

    The question you have is rather related to application logic and requirements and you can contact the Progress Professional Services for that to consult you most accurately. 

    As for your last question, you can check out this StakcOverflow thread: http://stackoverflow.com/questions/621235/using-htmlhelper-in-a-controller. I cannot guarantee this would work with the Kendo helpers, neither assure that they would work properly in such a scenario. The point of MVC is to have the view render the HTML, whereas the action to handle only data. By that, the entire pattern is bypassed, which is never a good practice. 

    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top