Sowmya Sirsi

Sowmya Sirsi

  • NA
  • 173
  • 40k

Action filter validation

Jul 9 2021 5:57 AM

Hi Team,

I am using  ActionFilter to validate the model in the code below.

public class ParentModelClass
{
    [Required]
    public string ReferenceID { get; set; }
    [Required]
    public string RequestedChannel { get; set; }
}

Controller

public class GetBanksController : ControllerBase 
{
    [ServiceFilter(typeof(ValidateModelAttribute))]
    [Authorize()]
    public ActionResult <GetBankResponse> GetBanks(GetBankRequest requestModel)
    {
        List<GetBankResponse> response = new List<GetBankResponse>();
        try
        {
            response= _unitOfWork.bankRepository.GetBanks(requestModel);
        }
        catch (Exception e)
        {
        }
    }
}

After testing in the postman getting validation response as below.

Can you please suggest me how to remove the lines marked with the yellow.

{

    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",

    "title": "One or more validation errors occurred.",

    "status": 400,

    "traceId": "00-aaf4c01700602d4bbeb0d019f656113d-7122bd4eba142544-00",

    "errors": {

        "ReferenceID": [

            "The ReferenceID field is required."

        ],

        "RequestedChannel": [

            "The RequestedChannel is invalid"

        ]

    }

}