About

Explain the demo and list a few features using a model generated by PowerShell.

Full source

File: pwsh/tutorial/examples/Assets/Pages/About.cshtml

@page
@model Kestrun.Razor.PwshKestrunModel
@{
    ViewData["Title"] = "About • Kestrun";
    dynamic d = Model.Data ?? new { Project = "Kestrun", Blurb = "No model", Features = new string[0] };
}

<div class="card">
    <h1>About @d.Project</h1>
    <p class="muted">@d.Blurb</p>
</div>

<div class="card">
    <h2>Features in this sample</h2>
    <ul>
        @foreach (var f in d.Features)
        {
            <li>@f</li>
        }
    </ul>
</div>

File: pwsh/tutorial/examples/Assets/Pages/About.cshtml.ps1

$Model = [pscustomobject]@{
    Project  = "Kestrun"
    Blurb    = "This sample uses Razor Pages for templating and PowerShell scripts as per-page model providers."
    Features = @(
        "Sibling script convention: Page.cshtml + Page.cshtml.ps1",
        "Per-request model via '$Model'",
        "Razor reads it as Model.Data",
        "Works under runtime compilation (C# 8 syntax in .cshtml)"
    )
}

Step-by-step

  1. View title: Set ViewData["Title"] for the layout.
  2. Model binding: Read Model.Data into d and define a fallback shape.
  3. Headline: Render the project name from the model.
  4. Blurb: Render a one-paragraph explanation.
  5. Features list: Iterate over d.Features and render each item.

Try it

curl -i http://127.0.0.1:5000/About

Troubleshooting

Symptom Cause Fix
Feature list is empty $Model.Features missing or empty Ensure About.cshtml.ps1 returns a Features array
Razor errors on foreach Model fallback type mismatch Keep Features = new string[0] (or ensure $Model.Features is an array of strings)

References


Previous / Next

Previous: Index Next: Status