简体   繁体   English

ASP.NET MVC在运行时生成动态表单字段的方法

[英]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. 我正在asp.net mvc中寻找推荐的方法和方法来在运行时生成动态字段。

1) if i design my own engine for it then how? 1)如果我为此设计自己的引擎,那又如何? 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? 2)有没有可能减少工作时间的框架? 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 用经过清理的值填充ViewBag
  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. 请记住,MVC表单处理可在键值列表上进行, Binder功能可将其转换为对象。 Saving data won't be difficult (dynamically created INSERT, UPDATE statement, ...). 保存数据将不会很困难(动态创建的INSERT,UPDATE语句等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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