首页 > 解决方案 > 无法将数据返回给邮递员

问题描述

我想从数据库中获取数据并将其返回给邮递员。在调试模式下,我可以看到有一些数据,但出于某种原因,我在邮递员中看不到它。

在此处输入图像描述

在此处输入图像描述

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

还有其他字段,如果评论我可以在邮递员中获取ProductsToCompare2 = ..

编辑 1

    [HttpPost]
    public async Task<IActionResult> GetProductComparsionByListId([FromBody] ProductComparsionVM comparsion)
    {
        return Json(await _productRepo.GetProductComparsionByListId(comparsion.ListId));
    }

标签: c#asp.net

解决方案


由于您将参数listId作为方法参数发送,因此 PostMan 中的值可以输入为form-data.

在此处输入图像描述


推荐阅读