Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

500 Error with async call

$
0
0

In my controller I have the following: and it working.

If I pull everything from the table it works:

[HttpGet]
public async Task<ActionResults> GetAll()
{
    return Json(new { data = await _dbConnection.Cars.ToListAsync() });


}

however, when I create LINQ query to only get certain columns returned, I get an 500 error. InvalidOperationException: Property 'JsonResults.SerializerSettings' must be an instance of type 'System.Text.Json.JsonSerializerOptions'

[HttpGet]
public async Task<ActionResults> GetAll()
{
   var q = _dbConnection.Cars;
   return Json(new
  {
    data = query
     .Task(20)
     .Select(x=> new
     {
          Make = x.Make,
          Model = x.Model,
          Type = x.ModelType  
     }) 

  }, await query.ToListAsync()); 
 
}


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>