Final code

Here's the final code.

@page "/birthday"

<h2>What's your date of birth?</h2>
<input type="text" @bind="dob" />
<button class="btn btn-primary" @onclick="Submit">Submit</button>
<hr />
@if (day != null)
{
    <p>You were born on a... @day!</p>
}

@code {
    private string dob = "";
    private string day;

    private void Submit()
    {
        if (dob != null)
        {
            var isValid = DateTime.TryParse(dob, out var date);
            if (isValid)
            {
                day = date.DayOfWeek.ToString();
            }
        }
    }
}

Give this a whirl in the browser:

  1. Enter a date
  2. Click Submit
  3. Marvel as Blazor renders the relevant day of the week!