Link to home
Start Free TrialLog in
Avatar of Seven price
Seven priceFlag for United States of America

asked on

but this dictionary requires a model item of type

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[MobileWeb.Models.ProductDetailsModel]', but this dictionary requires a model item of type 'MobileWeb.Models.ProductDetailsModel'.

Keep receiving this error, I see the data when it reaches the return view but I get this error.

 public class ProductDetails
    {

        public List<ProductDetailsModel> data { get; set; }
    }
    public class ProductDetailsModel
    {
               
        public string datanumber { get; set; }
        public string name { get; set; }
        public string description { get; set; }
        public string number { get; set; }
        public float avg_price { get; set; }

    }

Open in new window


  Stream objStream;
                objStream = wrGETURL.GetResponse().GetResponseStream();
              
                StreamReader objReader = new StreamReader(objStream);

                string sLine = "";
                int i = 0;
                WebResponse response = wrGETURL.GetResponse();
                string contentType = response.ContentType;
                //while (sLine != null)
                //{
                //    i++;
                sLine = objReader.ReadLine();
                 JObject o = JObject.Parse(sLine);
             //    Console.WriteLine("description: " + o["description"]);
                 List<ProductDetailsModel> mydata = new List<ProductDetailsModel>()
                 {
                   new ProductDetailsModel { description = (o["description"]).ToString() }
                 };

                 return View(mydata.AsEnumerable());

Open in new window

SOLUTION
Avatar of Camillia
Camillia
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Seven price

ASKER

List<ProductDetailsModel> mydata = new List<ProductDetailsModel>()
Line 112:                 {

Open in new window

Object reference not set to an instance of an object.

Recieving this error now
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok I need a little help with that, I can do that from a database but I have the data with sLine

how can I return the data description with this list
 List<LookupTable> mydata = new List<LookupTable>()
                 {
                   new LookupTable { description = (o["description"]).ToString() }
                 };

Open in new window

Ok it was simple I just had to

var model = new context
                 {
                   description =(o["description"]).ToString()
                 };