none
How to generate controls dynamically based on value stored in database using mvc4?

    Question

    1. 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.
    Friday, October 24, 2014 10:03 AM

Answers

  • They'll help you over here.

    Microsoft ASP.Net MVC forum

     

     

     


    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
    Moderator
  • 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>
                        }
            }

    Friday, October 24, 2014 2:05 PM

All replies

  • They'll help you over here.

    Microsoft ASP.Net MVC forum

     

     

     


    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
    Moderator
  • 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>
                        }
            }

    Friday, October 24, 2014 2:05 PM