AstrolUI AstrolUI
Yellow Orange Red Green Blue Purple Custom color
Light mode
Label

1. Demo AstrolLabel



@using Astrol.Component.Basic.Form
@using System.ComponentModel.DataAnnotations
 
<!-- Text from [Display(Name)]; clicking the label focuses the input with the same id -->
<AstrolLabel TItem="Login" For="@nameof(login.Password)" />
<input id="@nameof(login.Password)" type="password" class="aui-input" />
 
<!-- Typed expression and custom text -->
<AstrolLabel TItem="Login" ForExpression="x => x.User" Text="E-mail" />
<input id="@nameof(login.User)" type="email" class="aui-input" />
@code {
   public class Login { 
       public string User { get; set; } = string.Empty;
       [Display(Name = "Password")]
       public string Password { get; set; } = string.Empty;
   }
   private Login login = new Login();
}

Supported parameters

  • TItem (T), model whose property is described (required).
  • For (string), name of the TItem property; it is also used as the label's for attribute, so the input must have an id equal to that name, e.g. For="@nameof(Login.Password)".
  • ForExpression (Expression<Func<TItem, object?>>), typed alternative to For, e.g. ForExpression="x => x.Password"; used only when For is empty.
  • Text (string), label text; when not set, the Name of the property's [Display] attribute is used, or the property name if there is none.
  • ChildContent (RenderFragment), custom label content; when set, Text is ignored.
Markdown for AI © 2026 AstrolUI v10.0.13