How do I dynamically create an html table given only a table name in entity framework?

My code is more like creating an engine that when passed a table name variable, will construct the table dynamically. This is the code I'm already working on. In my controller,

public ActionResult ViewTable(string tablename)
            ScsContext context = new ScsContext();
            List<string> columnNames = new List<string>();

            var html = "<table><thead><tr>";

                case "table1":

                    columnNames = typeof(table1).GetProperties().Select(a => a.Name).ToList();

                    foreach(var c in columnNames)
                        html += "<td>" + c.ToString() + "</td>";

                    html += "</tr></thead><tbody>";

                    var rows = from c in context.table1.ToList()
                               select c;
                    foreach(var c in rows)
                        foreach(var p in c.GetType().GetProperties())
                            foreach(var s in columnNames)
                                if(p.Name == s.ToString())
                                    // How do I get the value here?



                // more case statements here based on table names

            // return empty for now
            return new EmptyResult();

Open in new window

I was able to loop the names of my columns in my entities, as above, and now constructing my html table based on those values.. but when I need to get the value now, I'm stucked. How do I get the value from my properties above to construct my html table based on table name variable?

And since I have more hundred tables the user want rendered, is there a simpler and more efficient way to do this?

Thanks very much,
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.