Variable required in Rest

0

I want to make a request with [post] and if any field is null I do not want to continue the service. I want to stop the flow in the controller, The problem arises in the modelstate.isvalid returns true when it should return false.

this is the code:

Model:

public class IdentityBrokerSettingsDetails
    {
        [Required(AllowEmptyStrings = false)]
        public string Tenant { get; set; }

        // With interrogation mark you make it nullable
        [Required]
        public bool? Account { get; set; }

        [Required]
        public bool? StatusUserLogin { get; set; }

        public IdentityBrokerSettingsDetails(string tenant, bool? account, bool? statusUserLogin)
        {
            Tenant = tenant;
            Account = account;
            StatusUserLogin = statusUserLogin;
        }
    }

Controller:

[HttpPost]
        public IActionResult PostIdentitySettingsDetails([FromBody] IdentityBrokerSettingsDetails identityBrokerSettingsDetails)
        {
            if (!ModelState.IsValid) //doesn't work
                return BadRequest();

        }
    
asked by CMorillo 22.10.2018 в 14:04
source

0 answers