Answered by:
How to generate controls dynamically based on value stored in database using mvc4?

Question
-
- In my database, i have a field called control_ids corresponding to text box, dropdownlist, radiobuttonlist etc. My goal is to create controls dynamically based on value of control_id-field in table. Anybody please help me how to create the controls dynamically in MVC 4 for this scenario.
- Moved by Dave PatrickMVP Friday, October 24, 2014 1:51 PM
Friday, October 24, 2014 10:03 AM
Answers
-
They'll help you over here.
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows]
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.Friday, October 24, 2014 1:51 PM -
In your view you could do something like that:
foreach (var field in Model.FormStruture.fields) { <div class="editor-label"> <label for="@field.Name">@field.Descricao</label> </div> <div class="editor-field"> <input class="text-box single-line" id="@field.Name" name="@field.Name" type="text" value="@field.Valor" data-rules-required="@field.Mandatory.ToString().ToLower()" data-rule-number="@field.Tipo.Equals(SiB.OCR.Documentos.Modelo.TipofieldDocumento.Numerico).ToString().ToLower()" title="@field.Descricao" /> </div> if (!String.IsNullOrEmpty(field.Format)) { @:<script type="text/javascript">$("#@field.Name").mask("@field.Format");</script> } }
- Proposed as answer by Deric Ferreira Friday, October 24, 2014 2:06 PM
- Marked as answer by Just Karl Friday, October 31, 2014 4:09 PM
Friday, October 24, 2014 2:05 PM
All replies
-
They'll help you over here.
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows]
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.Friday, October 24, 2014 1:51 PM -
In your view you could do something like that:
foreach (var field in Model.FormStruture.fields) { <div class="editor-label"> <label for="@field.Name">@field.Descricao</label> </div> <div class="editor-field"> <input class="text-box single-line" id="@field.Name" name="@field.Name" type="text" value="@field.Valor" data-rules-required="@field.Mandatory.ToString().ToLower()" data-rule-number="@field.Tipo.Equals(SiB.OCR.Documentos.Modelo.TipofieldDocumento.Numerico).ToString().ToLower()" title="@field.Descricao" /> </div> if (!String.IsNullOrEmpty(field.Format)) { @:<script type="text/javascript">$("#@field.Name").mask("@field.Format");</script> } }
- Proposed as answer by Deric Ferreira Friday, October 24, 2014 2:06 PM
- Marked as answer by Just Karl Friday, October 31, 2014 4:09 PM
Friday, October 24, 2014 2:05 PM