Short Tips (Published Every Day)

Table

Create table from object.

Component generates cells from public property which is: primitive, string, struct or nullable.

                    
                        @{
                            var obj = new object[]
                            {
                                new { Id = 1, Name = "W" },
                                new { Id = 2, Name = "K" },
                                new { Id = 3, Name = "Z" }
                            };
                        }
                        @Html.WB().Table().Bordered().AddRows(obj)
                    
                
Razor Code
1W
2K
3Z
Html Result

Table

Additional cell in existing rows.

Content in additional cell depends on other model property.

                    
                        @{
                            var obj2 = new User[]
                            {
                                new User(1, "W", true),
                                new User(2, "K", false),
                                new User(3, "Z", false),
                            };
                        }

                        @(Html.WB().Table().Bordered().AddRows(obj2, (m, row) =>
                        {
                            var wb = row.MvcService.WB;
                            var button = wb.LinkButton("Admin Panel", "#").Style(ButtonStyle.Primary).Size(ButtonSize.Sm);
                            return row.AddCell(cell => m.IsAdmin ? cell.Html(button) : cell);
                        }))
                    
                
Razor Code
1WTrueAdmin Panel
2KFalse
3ZFalse
Html Result

Table

Configure existing cell.

Third parameter allows configured what you show in every cell.

                    
                        @{
                            var obj3 = new User[]
                            {
                                new User(1, "W", true),
                                new User(2, "K", false),
                                new User(3, "Z", false),
                            };
                        }

                        @Html.WB().Table().Bordered().AddRows(obj2, (m, row) => row, (info, o, cell) =>
                        {
                            // info = PropertyInfo class of each property.
                            // o = actual cell property value.
                            // cell = cell to return.

                            if (o is bool b)
                            {
                                return b ? cell.Text("Yes") : cell.Text("No");
                            }

                            return cell.Text(o);
                        });
                    
                
Razor Code
1WYes
2KNo
3ZNo
Html Result