如何创建可变数量的文本框字段及其对应的标签 [英] How to create variable number of text box fields and their corresponding labels

查看:67
本文介绍了如何创建可变数量的文本框字段及其对应的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个asp.net mvc 5应用程序并需要一些帮助



假设以下型号:

I'm developing an asp.net mvc 5 application and need some help

Suppose the following model :

public class EmployeeMaster
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string F1 { get; set; }
    public string F2 { get; set; }
    public string F3 { get; set; }
    public string F4 { get; set; }
    public string Email { get; set; }
}



在管理员面板上,管理员将设置要保存在另一个数据库中的文本框及其相应标签的数量table,例如:(TextBoxLabel)。文本框和标签的这些变体出现在每个用户的帐户中,该帐户已分配了系统代码。现在,假设管理员想要分配2个文本框字段及其标签,那么,他只需转到管理区域并输入他想要的内容,现在在用户端(模型上方),它应该只显示4个文本框即(名称,F1,F2和电子邮件)忽略其他两个,F1和F2有自己的标签,这些标签将从TextBoxLabel表中从数据库中提取,这意味着当用户提交表单时,将填充F1和F2列,并且F3和F4将具有空值。



现在我的问题是如何实现上述场景,可能是实现此目的的简单和最佳方法,一个例子将深表感谢。在此先感谢:)


At the admin panel, the administrator will set the number of text boxes and their corresponding labels, that are going to saved in the database in another table, For instance : (TextBoxLabel). These variations of text boxes and labels occur for each user's account, that has been assigned a system code. Now, suppose if the administrator wants to assign 2 text box fields and their labels, so, he would simply go to the admin area and inputs it what he desires, now at the user's end (above model), it should simply display 4 textboxes namely (Name, F1, F2 and Email) neglecting the other two, F1 and F2 have their own labels that are to be fetched from database from TextBoxLabel table, that means that when the user submits the form the column F1 and F2 gets populated, and F3 and F4 will have null values.

Now my question is that how do I achieve the above scenario, what could be the simple and the best way to achieve this, an example would be deeply appreciated. Thanks in Advance :)

推荐答案

我有一个类似
的模型


I'd have a model like

public class EmployeeMaster
{
    public int Id { get; set; }
    public string Name { get; set; }
    public List<string> Fieldname { get; set; }
    public string Email { get; set; }
}





如果您想要两个名为Hello和World的字段,您可以将这两个字符串添加到字段名称列表。如果仅保留一个字符串是不够的,您可以使用包含键和值的Dictionary,或者使用您想要的字段创建自定义类,并存储其中的列表。



然后,您的视图将为字段名称列表中的每个项目创建一个文本框。



If you wanted two fields called "Hello" and "World" you'd add those two strings to the Fieldname List. If holding just one string isn't enough you could use a Dictionary that holds a key and a value, or create a custom class with the fields you want and store a list of that instead.

Your view would then create a textbox for each item in the Fieldname list.


这篇关于如何创建可变数量的文本框字段及其对应的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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