In my database, i have a field called controls which contains text box, dropdownlist, radiobuttonlist etc. My goal is to create controls dynamically based on value of control-field in table. Anybody please help me how to create the controls dynamically in MVC 4 for this scenario.
-
1Possible duplicate of Control creation based on model value in MVC4Umar Abbas– Umar Abbas2016-04-20 07:20:56 +00:00Commented Apr 20, 2016 at 7:20
-
here is sample code and also the demo page for creating dynamic controls in mvc.. hope this helps.. Create dynamic controls in MVCJeff D– Jeff D2017-01-19 17:11:36 +00:00Commented Jan 19, 2017 at 17:11
-
Possible duplicate of SimpleMembership with custom database schema in ASP.NET MVC 4Ashish Ratan– Ashish Ratan2018-03-09 11:21:55 +00:00Commented Mar 9, 2018 at 11:21
Add a comment
|
2 Answers
I used steps as mentioned in the below link and got an answer. Hope this will help someone.
Comments
-Create a template in Views/Shared/EditorTemplates for each control (textbox template below).
@model object
@Html.TextBoxFor(m=>m);
-Pass the template name into the Html.EditorFor helper method.
@Html.EditorFor(Function(x)=>x.Password,"templateName");
http://msdn.microsoft.com/en-us/library/ff406475(v=vs.118).aspx
9 Comments
user3793029
Thanks for your response. I try to implement your idea and update you the status.
user3793029
Can you please provide me some basic example?
user3793029
I am having another question too...Instead of control name, if i use control_id, then how to generate control dynamically based on this control_id stored in table. My Scenario is, user will have the option to select control type for their fieldname which is unknown others. After selecting control type( textbox,radiolist, etc...), corresponding control_id will be stored in table. Now based on the control_id stored in table, have to generate control dynamically...I am completely new to mvc. Can you please guide me in right direction to implement it?
user3793029
If my control_id is 1, it has to generate textbox and for 2, dropdownlist and for 3,4 accordingly. How to check these condition in controller action method..
Chris Perry
I am guessing you are trying to allow the user to define there own tables and now you want them to be able to add data? What is the use case?
|