An expression-bodied member is a C# member implemented by one expression after the expression-body operator. Because the member contains only an expression, it needs neither braces nor a return statement. This shorthand is commonly used for concise properties. section 3.2.2 section 2.8
The expression runs when the property is accessed, not when the containing page model is constructed. Code that initializes dependent state must therefore run before the property is read. section 3.2.2
Computed visibility property
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); public void OnGet() { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; } ShowRequestId derives its value from RequestId. The GET handler assigns RequestId before the Razor page evaluates ShowRequestId.
Conditional rendering in a form page
public bool ShowRenderedText => !string.IsNullOrEmpty(RenderedText); public void OnPost(string text) { RenderedText = FiggleFonts.Standard.Render( text ?? "Hello!"); } The Razor page reads ShowRenderedText to decide whether to display the rendered output.
