Exemplo n.º 1
0
        public static MvcHtmlString MyGrid(this HtmlHelper html, GridForViewModel model)
        {
            var content = "";

            //Table Header Done
            content += "<table class='table table-hover'><thead><tr>";
            foreach (var th in model.TypeObj.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (th.Name == "Id")
                {
                    continue;
                }
                content += $"<th>{th.Name}</th>";
            }

            content += "</tr></thead><tbody>";
            foreach (var obj in model.ListObj)
            {
                var fields   = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
                var fContent = "<tr>";
                foreach (var field in fields)
                {
                    if (field.GetValue(obj) != null)
                    {
                        fContent += $"<td>{field.GetValue(obj)}</td> ";
                    }
                }
                content += "</tr>" + fContent;
            }
            content += "</tbody></table>";

            return(new MvcHtmlString(content));
        }
Exemplo n.º 2
0
        public ActionResult Index2()
        {
            var admins = db.Admins.ToList();

            var vmodel = new GridForViewModel()
            {
                TypeObj = admins.First().GetType(),
                ListObj = admins.Cast <object>().ToList()
            };

            return(View("Index", vmodel));
        }
Exemplo n.º 3
0
        public ActionResult Index()
        {
            var users = db.Users.ToList();

            var vmodel = new GridForViewModel()
            {
                TypeObj = users.First().GetType(),
                ListObj = users.Cast <object>().ToList()
            };

            return(View(vmodel));
        }