jeudi 2 décembre 2021

I want to create IF ELSE statement for NULL formitems on Blazor

I wanted to create a handler that when the submit button is trigger it should add the record on the database but when the fields are Null or Empty it should throw an error. In my case it always passes. Codes are below:

 private async Task OnSubmitHandler(EditContext editContext)
    {
        AssigneeDto assigneeDto = editContext.Model as AssigneeDto;

        if (assigneeDto != null)
        {
            await _assigneeClient.CreateAssignee(sm.id, assigneeDto);
            NotificationReference.Show(new NotificationModel()
            {
                ThemeColor = ThemeColors.Success,
                Text = "Record Added Successfully!",
            });
            FormData = new AssigneeDto();
            CurrentForm = new EditContext(FormData);
            CurrentForm.AddDataAnnotationsValidation();
        }
        else
        {
            NotificationReference.Show(new NotificationModel()
            {
                ThemeColor = ThemeColors.Error,
                Text = "Record Could Not Be Added!",
            });
        }
    }

Aucun commentaire:

Enregistrer un commentaire