c# - Building dynamic view based on Fields retruned from DataBase in Asp.Net MVC3 -


I want to render the view on runtime based on the regions returned from the database. Any help should be appreciated, to design the prototype / approach

I have the model below,

  public class DynamicFields {public string propertyName {get ; Set; } Public string propertyType {get; Set; }}   

In the controller, this list

, so based on propertyType, I will need to provide control such as textbox / date time

thanks in advance propertyType

You create EditorTemplates for each value of propertyType Possible values ​​of

_textInput.cshtml (assuming text input propertyType )

  @moder DynamicFields @ Html.TextBoxFor (item = & gt; Model.propertyName)   

_dateTimeInput.cshtml (possible assuming dateTimeInput propertyType ) S)

  @model dynamikfilds@html. Textbox folder (item = & gt; model. Property name, new {class = "datetime"})   

View:

  @Emileumerable & lt; DynamicFields & gt; @forake (field in field) {@ Html.LabelFor (model = & gt; field.propertyName) @ Html.EditorFor (model => field.propertyName, field.propertyType) @ * Razor to use which More information can be found here:  

My answer has been updated with this answer on the foreach loop:

p>

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -