Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use the <code>this.ViewData.ModelMetadata.Properties</code> collection and call the <code>GetDisplayName</code> method to generate the header cell content. We do this generically in our code to render an arbitrary model as a table.</p> <p>Edit: To expand on this, I use a basic model that represents a table and only a table. I have 3 classes defined. I have a <code>TableRowCell' class, a</code>TableRow' class (which is essentially a collection of <code>TableRowCell</code> objects) and a <code>Table</code> class.</p> <pre><code>public class Table { public Table(String name) { this.Name = name; this.ContentRows = new List&lt;TableRow&gt;(); this.HeaderRow = new TableRow(); this.FooterRow = new TableRow(); } public IList&lt;TableRow&gt; ContentRows { get; private set; } public TableRow FooterRow { get; private set; } public TableRow HeaderRow { get; private set; } public String Name { get; private set; } } </code></pre> <p>When I have a view model that contains a collection of objects that I want to display in a table I call first an <code>HtmlHelper</code> extension that converts that collection into a <code>Table</code> object. Inside that method I iterate over a call to <code>ModelMetadataProviders.Current.GetMetadataForType(null, typeof(TModel)).Properties..Where(item =&gt; item.ShowForDisplay)</code> to get a collection of metadata objects used to generate the header cells. I then iterate over the collection of items and call <code>ModelMetadataProviders.Current.GetMetadataForType(() =&gt; item, typeof(TModel)).Properties..Where(item =&gt; item.ShowForDisplay)</code> to get a collection of metadata objects used to generate the content cells.</p> <p>Technically, my <code>HtmlHelper</code> extension method actually returns a <code>TableBuilder</code> object which will has a method called <code>Render</code> on it which generates the html. That setup has served me well so far.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload