c# - How to create a strongly typed view during runtime in ASP.NET MVC? -


i using asp.net mvc , there's need creates new views during runtime based on user selections. these views once created, need saved in storage can reused. prefer these views typed. naturally model class each new view doesn't exist , these classes have new properties according user creates.

for example, if user selects textbox , wants used firstname, have class created dynamically public property called firstname... , on. created on fly.

i ideas on how approach this. dynamic source code generation , compilation work workflow or complicating more should?

update:
1 use case if form needed created based on user selection of database table. if there hundreds of tables, won't creating hundreds of views. know can maybe use gridview in example cases, dynamic view more appropriate.

your user selections data, not code:

  • create data-structures based on user selections.
  • save them in database later.
  • write view takes data-structures (as model) , displays them.
  • editortemplates can used display each individual control, using strongly-typed views.

data

 public class page  {      public list<control> controls { get; set; }  }   public class textbox : control  {      public string label { get; set; }      public string value { get; set; }  } 

page.cshtml

@model page  @for (int 0; < model.controls.count; i++) {      // render using editortemplate view control's type      @html.editorfor(m => m.controls[i]) } 

editortemplates/textbox.cshtml

@model textbox  @html.hiddenfor(m => m.controlid)  @html.labelfor(m => m.value, model.label) @html.textboxfor(m => m.value) 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Website Login Issue developed in magento -

Can the constants be defined inside a model file of a framework in PHP? -