I want to do a request with [POST] and if some field it's null i don't follow to the Service. I want to stop the flow in the Controller. problem is with ModelState.IsValid it returns a true when it should be false and return a BadRequest
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();
}
Image what is happening: