35 lines
850 B
Plaintext
35 lines
850 B
Plaintext
<EditForm Model="@_model" OnValidSubmit="@OnValidSubmit">
|
|
<DataAnnotationsValidator />
|
|
|
|
<InputText @bind-Value="_model.Content" />
|
|
<ValidationMessage For=@(() => _model.Content) />
|
|
|
|
<button type="submit">Comment as @_username</button>
|
|
</EditForm>
|
|
|
|
@code
|
|
{
|
|
private AddCommentViewModel _model = new AddCommentViewModel();
|
|
|
|
[Parameter]
|
|
public string Username { get; set; }
|
|
|
|
[CascadingParameter]
|
|
private Task<AuthenticationState> authenticationStateTask { get; set; }
|
|
|
|
private string _username;
|
|
|
|
[Parameter]
|
|
public EventCallback<AddCommentViewModel> OnSubmit { get; set; }
|
|
|
|
protected async override Task OnInitializedAsync()
|
|
{
|
|
_username = (await authenticationStateTask).User.Identity.Name;
|
|
}
|
|
|
|
private async Task OnValidSubmit()
|
|
{
|
|
await OnSubmit.InvokeAsync(_model);
|
|
_model = new AddCommentViewModel();
|
|
}
|
|
} |