I do have a Blazor App with a Product Page. There are some products in the database that I do want to display when the Products tab is selected. However the products are not displayed.
However on LoadProducts i could not get anything from res.Value, there is no such thing. How to get the list on LoadProducts method?
private async Task LoadProducts()
{
try
{
var response = await ProductController.GetAllProducts();
var res = response.Result;
if (response.Value != null)
{
ProductsList = response.Value;
}
else
{
throw new Exception("Error: Unable to retrieve products.");
}
}
catch (Exception ex)
{
throw new Exception($"Error loading products: {ex.Message}");
}
}

Rositsa RusevaPosted Jun 16, 2024, 10:44 AM
Maybe there should be another solution
Rajendra TaradalePosted Jun 10, 2024, 5:09 AM
Also, check if this variable assignment is happening from any other places(for example default/ new initialization) - ProductsList
Jaimin ShethiyaPosted Jun 9, 2024, 6:38 AM
Hello,
Your function haven't return any list so you need to return that list.
Try below code
private async Task
> LoadProducts()
{
var productsList = new List();
try
{
var response = await ProductController.GetAllProducts();
var res = response.Result;
if (response.Value != null)
{
productsList = response.Value.ToList();
}
else
{
throw new Exception("Error: Unable to retrieve products.");
}
return productsList;
}
catch (Exception ex)
{
throw new Exception($"Error loading products: {ex.Message}");
}
}
Thanks
Vishal JoshiPosted Jun 9, 2024, 6:25 AM
Hello
Try to use ToList(). check out the below code sample
Thanks