Click here to Skip to main content
15,891,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm developing an asp.net mvc 5 application and need some help

Suppose the following model :
C#
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; }
}

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 :)
Posted

1 solution

I'd have a model like

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


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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900