'How can we show table names of database using dropdownlist in MVC and EntityFramework?
I need to show all the table names which are in my database into a dropdownlist.
When table is selected, I need to show another dropdownlist with columns. How can I do that?
I am using ASP.NET, MVC and EntityFramework.
Update : KnockoutJs: ASP.NET MVC 4 Dynamic Forms solved my dynamic dropdownlist problem.
Solution 1:[1]
Here is a KnockoutJs approach: ASP.NET MVC Dynamic Forms
Getting tables using Entity Framework:
using ( var ctx = new ObjectContext() )
{
List<string> results = ctx.ExecuteStoreQuery<string>("SELECT name FROM sys.tables ORDER BY name").ToList();
}
Then just bind your results to a DropdownList. Knockout documentation is pretty good. Here is how to bind values to select/option
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
