Home > Mobile >  There is no REQUIRED field on the attribute of a view model but still form submission fails .Net 6
There is no REQUIRED field on the attribute of a view model but still form submission fails .Net 6

Time:03-02

This is view model through which I am passing data :

 public class DriverRegisterViewModel
  

    {
            [Required]
            public string Name { get; set; }
            [Required]
            [EmailAddress]
            public string Email { get; set; }
            [Required]
            public string Password { get; set; }
            public string MechanicTypesNames { get; set; }
            public string Location { get; set; }
            public string Latitude { get; set; }
            public string Longitude { get; set; }
    }

and facing the following error in response :

errors: {Latitude: ["The Latitude field is required."], Location: ["The Location field is required."],…}
status: 400
title: "One or more validation errors occurred."
traceId: "00-8c51a8400365bcce1564833f6a2659bd-492eeda6ab8c61f1-00"
type: "https://tools.ietf.org/html/rfc7231#section-6.5.1"

CodePudding user response:

use [ValidateNever] attribute on fields that are not Required.

  • Related