Home To get a column name of a table in mvc view using entity framework
Reply: 0

To get a column name of a table in mvc view using entity framework

ITBeginner Published in 2018-02-14 06:37:54Z

How to get a column name from a table using entity framework and displayed in a view? Please help me on this... IN MVC 5. I am new to MVC, please help me how to write a controller and view to get a column name of a database table and displayed it in a view.... For example : I have a Registration table in mysql, i want all field_names like Id, Name, Email, Phone, ...etc., from Registration table and displayed in a view. please assist on this

Controller :

public ActionResult Column()
            using (RegistrationEntities db = new RegistrationEntities())

         var names = typeof(Registration_tbl).GetProperties().Select(property => property.Name).ToArray();

                ViewBag.MyTables = names;
                return View(names);


View :

    ViewBag.Title = "Column";


@foreach (string name in ViewBag.MyTables)

now i am Got the output...list of columns displayed..Please help me... how to pass the dropdown list value in this function **typeof("")... instead of hard code Registration_tbl...i pass the Registration_tbl value via dropdown list... in this line i want to pass dropdownlist value..

var names = typeof(Registration_tbl).GetProperties().Select(property => property.Name).ToArray();

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.327942 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO