Bedingte Validierung Blazor WASMC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Bedingte Validierung Blazor WASM

Post by Anonymous »

I have a Blazor Wasm app that I use with an ASP.Net Core API.

I have one page with a form that I use Blazors built in validation with (data annotations and so on).

However now I have added a new feature and I don't know how to solve the validation any more.

The nu feature is that the user can choose to either choose a value in a dropdown Menü (dies wurde von Anfang an vorhanden und ist erforderlich) oder klicken Sie auf eine Schaltfläche und geben Sie einige Werte ein. If the user clicks the button and enter the values needed the dropdown is no longer required.

I have no idea on how to solve this conditional validation. I have tried to read MS documentation but they don´t really cover this and other googling has not help either.

Image

For other features on the same Form I use EditContext for the EditForm element instead of a model.

If the user clicks the button and fills in the form correctly an otherwise empty Object is instantiated

Do anyone have a solution for this?
The model used in the EditForm is this:

Code: Select all

public class NewJobDTO
{
[Required(ErrorMessage = "A hash file must be added")]
public string HashFileName { get; set; }
public string? JobName { get; set; }
public string HashFileContent { get; set; }
[Required]
[Range(0, 99999)]
public int HashType { get; set; }
// [Required(ErrorMessage = "Please select a Dictionary")]
// [Range(1, 20, ErrorMessage = "Please select a Dictionary")]
public int Dictionary { get; set; }
[Required(ErrorMessage = "Please select a Rule")]
[Range(1, 2, ErrorMessage = "Please select a Rule")]
public int Rule { get; set; }
[Required]
[EmailAddress]
[Display(Name = "Email address")]
public string Owner { get; set; }
[Required(ErrorMessage = "A public gpg key file must be added")]
public string KeyFileName { get; set; }
public string KeyFileContent { get; set; }
}
< /code>
Teile des Formulars: < /p>




Select dictionary to use
@if(wordlists.Count != 0)
{
@foreach (var dict in wordlists)
{
@dict.Name (@GetSize(dict.Size))
}
}

Dictionary*
@if(newJob.Dictionary != 0)
{
@wordlists.Where(w => w.Id == newJob.Dictionary).First().Description
}


Use Cewl


Submit

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post