Wsu.Asis.AutoDisplay.Web 1.0.0.2

dotnet add package Wsu.Asis.AutoDisplay.Web --version 1.0.0.2
                    
NuGet\Install-Package Wsu.Asis.AutoDisplay.Web -Version 1.0.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Wsu.Asis.AutoDisplay.Web" Version="1.0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Wsu.Asis.AutoDisplay.Web" Version="1.0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Wsu.Asis.AutoDisplay.Web" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Wsu.Asis.AutoDisplay.Web --version 1.0.0.2
                    
#r "nuget: Wsu.Asis.AutoDisplay.Web, 1.0.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Wsu.Asis.AutoDisplay.Web@1.0.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Wsu.Asis.AutoDisplay.Web&version=1.0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Wsu.Asis.AutoDisplay.Web&version=1.0.0.2
                    
Install as a Cake Tool

AutoDisplay.Web

This contains tools to automatically generate HTML tables and Description Lists.

For ASP.NET Core to pick up on the tag helpers, You need to add this to your _ViewImports.cshtml:

@addTagHelper *, AutoDisplay.Web

Tables

To generate a table, use the asp-for giving an IEnumerable<T> or a DataTable:

<table asp-for="MyList"></table>

The asp-for value is a ModelExpression, but it also can be used with non-model properties by using an @:

<table asp-for="@myList.Where(i => i.Whatever)"></table>

Description Lists

Description lists will display the properties of an object or the key/value pairs in an IDictionary:

<dl asp-for="Thing"></dl>

Like with tables, the asp-for value is a ModelExpression, but it also can be used with non-model properties by using an @:

<dl asp-for="@things.First()"></dl>

This means it's possible to use foreach to display a list of objects for when there are too man properties for a table or to make a list of items more mobile friendly:

<ul>
	@foreach (var thing in this.Model.Things)
	{
		<li>
			<dl asp-for="@thing"></dl>
		</li>
	}
</ul>

Links can be created by using attributes that implement IAutoDisplayLinkGenerator and additional route values can be added with attributes that implement IAutoDisplayRouteValueGenerator. A few attributes are built in.

For IAutoDisplayLinkGenerator:

  • AutoDisplayUrlLinkAttribute for using a static URL base. This is passed to string.Format along with the property value.

    [AutoDisplayUrlLink("https://example.com/{0}")]
    public int Id { get; set; }
    
  • AutoDisplayPageLinkAttribute for generating links to razor pages. The name of the razor page route data parameter is also needed.

    [AutoDisplayPageLink("/Things/View", "ThingId")]
    public int Id { get; set; }
    

For IAutoDisplayRouteValueGenerator:

  • AutoDisplayStaticLinkRouteValueAttribute for providing a static value

    [AutoDisplayPageLink("/Things/ByStatus", "Status")]
    [AutoDisplayStaticLinkRouteValue("ResultsPerPage", "50")]
    public ThingStatus Status { get; set; }
    
  • AutoDisplayPropertyLinkRouteValueAttribute for referencing another property in the same object to use as a route value

    [AutoDisplayPageLink("/Things/ByStatus", "Status")]
    [AutoDisplayPropertyLinkRouteValue("ResultsPerPage", nameof(ResultsPerPage))]
    public ThingStatus Status { get; set; }
    
    public int ResultsPerPage { get; set; }
    

CSS Classes

CSS classes can also be applied to the result container (<td> or dd) or to a generated link using CssClassAttribute and LinkCssClassAttribute.

[AutoDisplayPageLink("/Things/View", "ThingId")]
[AutoDisplayLinkCssClass("linkClass")]
public int Id { get; set; }

[AutoDisplayCssClass("propertyClass")]
public string Name { get; set; }

Formatting Output

How the value and property names are displayed can be controlled with attributes.

  • By default, the name of the property will be used as the display name. This can be changed with a DisplayAttribute:

    [Display(Name = "Thing ID")]
    public int ThingId { get; set; }
    
  • Enums use the name by default, but the display value can also be set using a DisplayAttribute:

    public enum MyOptions
    {
      [Display(Name = "Option 1")]
      Option1,
      [Display(Name = "Option 2")]
      Option2,
      [Display(Name = "Option 3")]
      Option3
    }
    
  • A DataFormatAttribute can be used to specify formatting for the property. This get used with string.Format.

    [DisplayFormat(DataFormatString = "{0:yyyyMMdd}")]
    public DateTime Created { get; set; }
    
  • A DataFormatAttribute can also be used to specify what to display when the value is null:

    [DisplayFormat(NullDisplayText = "None")]
    public int? Size { get; set; }
    
  • A DataTypeAttribute can also be used to change the format:

    [DataType(DataType.Currency)]
    public decimal Amount { get; set; }
    [DataType(DataType.EmailAddress)]
    public string? EmailAddress { get; set; }
    
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0.2 212 2/8/2025
1.0.0.1 242 8/14/2024
1.0.0 189 8/8/2024