testWP-02
testWP-02

Reputation: 1

How can I fix the method so that they process the list?

I have a model with a list, and I am trying to write a code to process the list, but nothing comes out. How can I fix or improve the method? I'm a beginner.

Code in model

public List<string> Poster { get; set; }

And my method

public async Task<ActionResult<int>> Post(News news){
    if (!string.IsNullOrWhiteSpace(news.Poster))
                {
                    var productPhoto = Convert.FromBase64String(news.Poster);
                    news.Poster = await _fileStorageService.SaveFile(productPhoto, "jpg", "news");
                }
...

Upvotes: 0

Views: 60

Answers (1)

Oliver
Oliver

Reputation: 45101

Your property Poster is a list, but in your method you use it like a single string. I think you need to iterate over the list:

foreach(var entry in news.Poster)
{
    if(!string.IsNullOrWhitespace(entry))
    {
        // ...
    }
}

Upvotes: 1

Related Questions