0

下一个 api 在 Postmen 中返回并返回给客户端 item1,item2 当我使用 ValueTuple 更改名称时(名称不太重要,但我无法返回 item1,item2)

public async Task<(List<CategoryFilterResponseDTO> categoryFilters, string MetaDataDescription)> GetCategoryFilterPage([FromBody]categoryFilterRequestDTO categoryFilterRequest)
{
    var logItem = new LogDTO();
    var result = await _service.GetCategoryFilterPage(categoryFilterRequest);

    try
    {
        OnStart(logItem, new object[] { categoryFilterRequest });
        var categoryFilters = result.categoryFilters;
        var MetaDataDescription = result.MetaDataDescription;


        return (categoryFilters: categoryFilters, MetaDataDescription: MetaDataDescription);

    }
}

方法:

public async Task<(List<CategoryFilterResponseDTO> categoryFilters, string MetaDataDescription)> GetCategoryFilterPage(categoryFilterRequestDTO categoryFilterRequestDTO)
{
    List<CategoryFilterResponseDTO> categoryFilter = new List<CategoryFilterResponseDTO>();
    List<FavoriteDTO> isFavorite = null;
    string MetaDataDescription = "";
    (List<FilterSortDTO<FlatSearchCategory>>, int) searchCategory = await _clubRepo.CategoryFilterPage(categoryFilterRequestDTO);//BranchesCount
    if (searchCategory.Item2 == 0)
    {
        MetaDataDescription = GetCategoryDetails(categoryFilterRequestDTO.CategoryFirstFatherID.Value).CategoryName;
        return (categoryFilters: categoryFilter, MetaDataDescription: MetaDataDescription);
    }
4

2 回答 2

2

您可以将退货更改为以下内容:

return Ok(new
{
    categoryFilters = categoryFilter,
    metaDataDescription = MetaDataDescription
});

您还需要将返回类型更改为ActionResult或类似。

于 2019-11-11T10:06:36.120 回答
1

因为这是 a 上字段的名称ValueTuple<,>

赋予这些值的名称仅适用于源代码。

于 2019-11-11T13:15:43.757 回答