71 lines
2.0 KiB
Plaintext
71 lines
2.0 KiB
Plaintext
@page "/servers/{id:int}"
|
|
@* Route constraints: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-9.0#route-constraints *@
|
|
|
|
@attribute [ExcludeFromInteractiveRouting]
|
|
|
|
@inject NavigationManager NavigationManager
|
|
|
|
<h3>Edit server</h3>
|
|
<br/>
|
|
<br/>
|
|
|
|
@if (server != null)
|
|
{
|
|
<EditForm Model="server" FormName="formServer" OnValidSubmit="SubmitServer">
|
|
<DataAnnotationsValidator></DataAnnotationsValidator>
|
|
<ValidationSummary></ValidationSummary>
|
|
<InputNumber @bind-Value="server.Id" hidden></InputNumber>
|
|
|
|
<FieldComponent Label="Name">
|
|
<Control>
|
|
<InputText @bind-Value="server.Name" class="form-control"></InputText>
|
|
</Control>
|
|
<ValidationControl>
|
|
<ValidationMessage For="() => server.Name"></ValidationMessage>
|
|
</ValidationControl>
|
|
</FieldComponent>
|
|
|
|
<FieldComponent Label="City">
|
|
<Control>
|
|
<InputText @bind-Value="server.City" class="form-control"></InputText>
|
|
</Control>
|
|
<ValidationControl>
|
|
<ValidationMessage For="() => server.City"></ValidationMessage>
|
|
</ValidationControl>
|
|
</FieldComponent>
|
|
|
|
<FieldComponent Label="Online">
|
|
<Control>
|
|
<InputCheckbox @bind-Value="server.IsOnline" class="form-check-input"></InputCheckbox>
|
|
</Control>
|
|
</FieldComponent>
|
|
<br/>
|
|
<button class="btn btn-primary" type="submit">Update</button>
|
|
|
|
<a href="/servers" class="btn btn-primary">Close</a>
|
|
</EditForm>
|
|
}
|
|
|
|
@code {
|
|
[Parameter] // This is a root parameter.
|
|
public int Id { get; set; }
|
|
|
|
[SupplyParameterFromForm(FormName = "formServer")]
|
|
private Server? server { get; set; }
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
server ??= ServersRepository.GetServerById(this.Id);
|
|
}
|
|
|
|
private void SubmitServer()
|
|
{
|
|
if (server != null)
|
|
{
|
|
ServersRepository.UpdateServer(server.Id, server);
|
|
}
|
|
|
|
// An exception is raised when debugging from VS Code, but not when using dotnet watch.
|
|
NavigationManager.NavigateTo("/servers");
|
|
}
|
|
} |