如何使用mvc4基于数据库中的值动态创建控件 [英] how to create controls dynamically based on value in database using mvc4

查看:92
本文介绍了如何使用mvc4基于数据库中的值动态创建控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中,我有一个名为controls的字段,其中包含文本框,下拉列表,radiobuttonlist等。我的目标是根据表中的控制字段值动态创建控件。任何人请帮助我如何在MVC 4中为此方案动态创建控件。

解决方案

1.您应该首先创建一个包含在其中的ControlModel类属性控件所需的所有信息。



2.然后直接在控制器上间接执行,你应该根据你的ControlModel类创建一个列表数据库中存在的数据。



3.之后你必须创建一个视图,其中包含 Model 上面第二点创建的ControlModel对象列表,以及 foreach 使用此列表动态构建视图。请注意,通常新创建的控件应与控制器中的操作链接。



4.最后在控制器类中,您应该实现在第3点创建的控件操作

In my database, i have a field called controls which contains text box, dropdownlist, radiobuttonlist etc. My goal is to create controls dynamically based on value of control field in table. Anybody please help me how to create the controls dynamically in MVC 4 for this scenario.

解决方案

1.You should start by creating a "ControlModel" class that contains in its properties all info needed for your controls.

2.Then directly, on indirectly in/from your controller, you should create a list of your "ControlModel" class based on the data existing in your database.

3.After that you have to create a view that has as its "Model" the list of "ControlModel" objects created as 2nd point above, and into a foreach use this list to build dynamically the view. Note that normally your new created controls should be linked with actions from your controller.

4.Finally in your controller class you should implement your controls actions created at 3rd point above.


这篇关于如何使用mvc4基于数据库中的值动态创建控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆