簡體   English   中英

無法將數據返回給郵遞員

[英]Can't return data to 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; }
}

還有其他字段,如果評論ProductsToCompare2 = ..

編輯 1

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

由於您將參數listId作為方法參數發送,因此listId中的值可以作為form-data輸入。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM