与动态表单的ASP.NET MVC咨询 [英] Advice with Dynamic Forms in ASP.NET MVC
问题描述
我的工作呈现一个动态的形式在一个ASP.NET MVC视图,将符合下列要求:
I am working on rendering a dynamic form in an ASP.NET MVC view that will meet these requirements:
- 字段可以验证
- 国家是preserved当表单无效
我期待到创建自定义模型绑定来实现这一目标。一般我打算做到这一点:
I am looking into creating a custom model binder to achieve this. I am generally planning to do this:
- 在表单域与这些属性进行定义
- 提示符(标签旁边场)
- 类型(文本,的CheckBoxList,单选列表,等等。)
- 选择(单场)
- IsRequired
- RegularEx pression(对于文本字段)
- 在显示选项
- Form fields are defined with these properties
- Prompt (label next to fields)
- Type (text, checkboxlist, radiolist, etc.)
- Choices (for list fields)
- IsRequired
- RegularExpression (for text fields)
- Display Options
- 如果需要 - >必须有一个值
- 如果正则表达式 - >必须匹配
- 对于每个字段无效,被添加一个错误消息到ModelState中
- 如果所有的字段都有效
- 在做任何的字段及其值
- If all fields are valid
- Do whatever with the fields and their values
- 发送字段集合回查看
- 再次渲染领域,用自己的previously尝试值
- 显示验证摘要
我不知道如果我这样做的最好的或最简单的方法。请问这种做法给了我很多问题,甚至工作?我能做些什么来改善呢?
I'm not sure if I am doing this in the best or easiest way. Will this approach give me a lot of problems or even work? What can I do to improve upon it?
推荐答案
我写了一个类库,基本上不正是我的伪code。在我的问题描述。它的伟大工程。
I wrote a class library that basically does exactly what my psuedocode in my question describes. It works great.
我终于可以清理我的类库。我增加了一些新的功能,并创建了一个相当有据可查的演示Web应用程序。
I finally got around to cleaning up my class library. I have added some new features and created a fairly well documented demo web application.
所有这一切都在这里托管在codePLEX 。我希望这可以帮助别人。
All of this is hosted here on CodePlex. I hope this helps someone.
这篇关于与动态表单的ASP.NET MVC咨询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!