This is a migrated thread and some comments may be shown as answers.

Dynamically add controls to page

2 Answers 921 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 05 May 2017, 10:12 PM

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.

@(Html.Kendo().NumericTextBox<decimal>().Name("currency").Format("c"))
@(Html.Kendo().NumericTextBox<decimal>().Name("currency2").Format("c").Value(50))

 

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" />
 
<script>
  $(document).ready(function() {
    $("#currency").kendoNumericTextBox({format: "c"});
    $("#currency2").kendoNumericTextBox({format: "c"});
  });
</script>

 

2 Answers, 1 is accepted

Sort by
0
Tom
Top achievements
Rank 1
answered on 05 May 2017, 10:16 PM
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?
0
Ianko
Telerik team
answered on 10 May 2017, 12:37 PM

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 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. 

Regards,
Ianko
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.
Tags
General Discussions
Asked by
Tom
Top achievements
Rank 1
Answers by
Tom
Top achievements
Rank 1
Ianko
Telerik team
Share this question
or