简体   繁体   中英

asp.net mvc ways for generating dynamic form fields at runtime

在此处输入图片说明

this is the more or less the schema i want to generate my dynamic form on based on the fields above. i am going to add the direction , max size, default value and like wise some more fields in it. i am looking for recommended ways and methods in asp.net mvc for generating dynamic fields at runtime.

1) if i design my own engine for it then how? i am interested on that also but this is the last thing i am looking at. method to apply validation is very important in my scenario

2) any framework that may lessen the working time? or anything else?

I'll describe the generic approach, I don't want to code it for you.

  1. Create meta class to describe each field (type, name, maxlength, null value handling, data source for combos, etc.)
  2. Load the data from database and preprocess it
  3. Populate the ViewBag with sanitized values
  4. Create helper that will generated the control specific code

     Html.ControlFor("Name", metadata); 
  5. Loop in view over the metadata collection.

which will generate textbox, combobox, etc.

Remeber that MVC form handling works over list of key-values, it's the Binder feature that converts it to objects. Saving data won't be difficult (dynamically created INSERT, UPDATE statement, ...).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM