2

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.

3

2 Answers 2

2

I used steps as mentioned in the below link and got an answer. Hope this will help someone.

Control creation based on model value in MVC4

Sign up to request clarification or add additional context in comments.

Comments

0

-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

Thanks for your response. I try to implement your idea and update you the status.
Can you please provide me some basic example?
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?
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..
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?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.