Reputation: 11
i have 2 model classes
public class ProductOptionRequest
{
public string Name { set; get; }
public List<ProductValuesRequest> productValues { get; set; }
}
public class ProductValuesRequest
{
public string ValueName { get; set; }
}
public class ProductOptionValue
{
public int OptionId { get; set; }
public String ValueName { get; set; }
[Timestamp]
public byte[] RowVersion { get; set; }
}
and wrote one bs method and passing parameter value as value names. but I'm unable to get those values in a list object as productValues. May I know the solution, please.
public async Task<ReturnString> SaveProductOption(ProductOptionRequest request)
{
request.productValues = new List<ProductValuesRequest>();
foreach (ProductValuesRequest valueRequest in request.productValues)
{
ProductOptionValue res = new ProductOptionValue();
res.ValueName = valueRequest.ValueName;
object response = await productOptionValueRepository.InsertAsync(res, true);
}
}
Upvotes: 0
Views: 91
Reputation: 31
You are assigning an emplty list to productValues as request.productValues = new List() and trying to iterate the empty list.
Upvotes: 1
Reputation: 3820
In the first line of your method, you are replacing the productValues
property of request
object with a new empty list, :
request.productValues = new List<ProductValuesRequest>();
Therefore, in foreach
loop, you are iterating on an empty list.
Remove the first line and see if you still have any issues.
Upvotes: 1