I want to return a table and the number of rows present in the table as a response

157 views Asked by At

I have to send the noOfRecords variable in the response.

public HttpResponseMessage GetWareHouses(int pageNumber, int noofRows) 
{ 
var result = myModelObject.SelectTableData(pageNumber, noofRows); 
int numberOfRec = result.Count; /*I need to send this data in response.*/ 
if(numberOfRec>0) 
return  Request.CreateResponse(HttpStatusCode.OK, result) 
} 
1

There are 1 answers

1
Derviş Kayımbaşıoğlu On

In your function, there are at least two problems.

  1. All paths needs to return a value. In your function, It is not.
  2. If you are using Controllers to return value, I advice you to use IActionResult

thus

public IActionResult GetWareHouses(int pageNumber, int noofRows) 
{ 
    var result = myModelObject.SelectTableData(pageNumber, noofRows); 
    int numberOfRec = result.Count; 

    if(numberOfRec>0) 
        return Ok(result) ;

    return BadRequest("problem");
}