-1

在我的 MVC 项目中,我从 WEB API 接收数据。

public ActionResult Index()
{
    if (Session["LoggedInUser"] == null)
    {
        var Data = GetPublicationsData();
        return View(Data);
    }
    else
    {
        return View();
    }
}
public ProductCategoryInfo GetPublicationsData()
{
    ProductCategoryInfo model = new ProductCategoryInfo();
    // Fetch Data from WEB API AND RETURN MODEL

    IRestResponse response = client.Execute(request);
    ProductCategoryInfo responses = JsonConvert.DeserializeObject<ProductCategoryInfo>(response.Content); 
            
    return model;
}

成功从 Web API获取数据,但是当我检查VAR DATA变量时,它显示为null

4

1 回答 1

1

您必须修复一个错误,将 ProductCategoryInfo response = ... 替换为

   var model = JsonConvert.DeserializeObject<ProductCategoryInfo>(response.Content); 
            
   return model;
于 2021-07-27T16:02:24.483 回答