Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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.
Posted
Updated 23-Oct-14 0:40am
v2
Comments
CHill60 23-Oct-14 7:08am    
What have you tried and where are you stuck?

1 solution

1.You should start by creating a "ControlModel" class that contains in its properties all info needed for your controls.

2.Then directly, on indirectly in/from your controller, you should create a list of your "ControlModel" class based on the data existing in your database.

3.After that you have to create a view that has as its "Model" the list of "ControlModel" objects created as 2nd point above, and into a foreach use this list to build dynamically the view. Note that normally your new created controls should be linked with actions from your controller.

4.Finally in your controller class you should implement your controls actions created at 3rd point above.
 
Share this answer
 
v2
Comments
Member 11174491 23-Oct-14 8:02am    
Thanks for your response. I am completely new to mvc. Can you please provide me some example?
Raul Iloc 23-Oct-14 8:56am    
Sorry, but I don't have time to implement all of this, but there a lot of MVC articles with source code on this site (I also have 4 MVC articles) and you could use some of them as examples.
Member 11174491 24-Oct-14 3:47am    
Thank you for giving me some direction to get an idea.
Raul Iloc 24-Oct-14 4:21am    
Welcome! I am glad that I could help you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900