Conversion error when trying to popular a variable

Asked

Viewed 36 times

1

I have it:

model.Items = new List<CatalogItemResponse>() { qryMode };

gives error because qryMode is of type Catalogitemresponse and not a list of the Catalogitemresponse

How to inputo qryMode into model?

  • 1

    I realized that the "downvotes" are ALMOST ALWAYS for Microsoft product posts (VB, C#, etc...) ... weird, right?

  • I gave an Addrange(qryMode) and I’ll test

  • Apparently your code is correct, I even made a test code on dotnetFiddle and it worked correctly: https://dotnetfiddle.net/8dX2IX

  • 1

    I’ve seen cases of questions with +30 up on Soen, here the question looked like -3. About the question, model.Items is already instantiated? If yes, just give an add(qryMode).

  • It did not function, but I saw some strange things. I will debug and post, but as I assign the object in a list?

  • There’s nothing wrong with your code. I validated it locally with test code and it works perfectly. There’s something else there!

  • I think that’s missing: model.Items = new List<CatalogItemResponse>() and then model.Items.AddRange(qryMode)

  • I will remove the comments of vent, as they are outside the scope of the site, but I was really upset. And then remove this too

  • What was missing in the question was specifying which qryMode was a list. That’s why Addrange worked. Without this information it would be difficult for anyone to help.

Show 4 more comments

1 answer

0

If model.Items be the type List<CatalogItemResponse>, try this:

model.Items = new List<CatalogItemResponse>();
model.Items.Add(qryMode);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.