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
Post a Comment