Search code examples
c#asp.net-core.net-coreentity-framework-6.net-5

Cannot return badrequest mvc in the controller


Why Can't I return a bad request here? In other examples it works just fine.

[HttpGet("getPrediction/{dateTime}/{filterUnit}/{filterLocation}/{filterContent}")]
public int GetFillLevelForDateTime(string dateTime, bool filterUnit, int unit, bool filterLocation,
    double latitude, double longitude, bool filterContent, string containerContent)
{
    try
    {
        bool tempExists = predictionService.CheckIfMessagesExist(unit, latitude, longitude, filterUnit, filterLocation);
        if (tempExists)
        {
            return GetFillLevelPrediction(dateTime, filterUnit, unit, filterLocation, latitude, longitude, filterContent, containerContent);
        }
    } catch (Exception ex)
    {
        return BadRequest();
    }
}

Solution

  • Change your action header

      public ActionResult<int> GetFillLevelForDateTime ....