简体   繁体   English

无法将数据返回给邮递员

[英]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 = ..还有其他字段,如果评论ProductsToCompare2 = ..

Edit 1编辑 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 .由于您将参数listId作为方法参数发送,因此listId中的值可以作为form-data输入。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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