mercredi 27 mai 2020

Web API model validation based on paramters

I have API like this , what i want his When i call with out any parameters http//localhostcustomer/employes/ it should return StatusCode(StatusCodes.Status404NotFound)

And if pass with invalid parameters http//localhostcustomer/employes/customerid=abcsd&employedid=yyyy it should return StatusCode(StatusCodes.Status400BadRequest);

how to do model validation for this

[Route("customer/employes")]
Public class testcontroller : controller

public List<Emplyees> get( [Required]int customerid, [Required]int employedid)
{

  if (ModelState.IsValid)
return OK
else
StatusCode(StatusCodes.Status400BadRequest);

}



Aucun commentaire:

Enregistrer un commentaire