[SOLVED] There is no REQUIRED field on the attribute of a view model but still form submission fails .Net 6

Issue

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"

Solution

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

Answered By – Aay Que

Answer Checked By – Willingham (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *