简体   繁体   中英

Can't return data to postman

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));
    }

Since you are sending the parameter listId as method parameter the value in PostMan can be entered as form-data .

在此处输入图片说明

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM