I want to get data from the database and return it to postman. In debug mode I can see that there is some data, but by some reasom I don't see it in postman.
public async Task<ProductComparsionVM> GetProductComparsionByListId(int listId)
{
var comparsionList = _dbContext.ProductsComparsion.Include(z => z.ProductsToCompare).FirstOrDefault(z => z.Id == listId);
if (comparsionList == null)
return null;
var category = _dbContext.Categories.FirstOrDefault(z => z.Id == comparsionList.CategoryId);
var tmp = new ProductComparsionVM
{
ProductsToCompare2 = comparsionList.ProductsToCompare.ToList()
};
return tmp;
}
public class ProductComparsionVM
{
public int CategoryId { get; set; }
public string CategoryName { get; set; }
public int ListId { get; set; }
public int ProductId { get; set; }
public List<int> ProductsToCompare { get; set; }
public List<ProductToCompare> ProductsToCompare2 { get; set; }
}
There is other fields, which I can get in postman if comment ProductsToCompare2 = ..
Edit 1
[HttpPost]
public async Task<IActionResult> GetProductComparsionByListId([FromBody] ProductComparsionVM comparsion)
{
return Json(await _productRepo.GetProductComparsionByListId(comparsion.ListId));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.