0

Razor UI validation isnt working at all. When i go to post with empty text boxes it should say that this field is required but it just allows it to go through.

Trying to validate for the PageModel.

AddApplication.cshtml.cs

        [DataType(DataType.Text)]
        [BindProperty]
        public string appName{get;set;}

AddApplication.cshtml

<input type="text" asp-for="appName" placeholder="Enter Application Name" class="form-control" style="width:25%">
<span asp-validation-for="appName" class="text-danger"></span>

I already have the services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); included in the start up so i don't understand why this isn't working.

Ajay Singh
  • 63
  • 10

1 Answers1

0

Within your getter and setter you need to state that appName is required so it cannot be left blank.

[Required(ErrorMessage = "App Name Is Needed")]
public string appName{get; set;}

Without that the name can be left blank as you have seen. With this it should throw an error message after submission that the App Name Is Needed.