What does this model error says in asp.net mvc?

Posted by Pandiya Chendur on Stack Overflow See other posts from Stack Overflow or by Pandiya Chendur
Published on 2010-05-01T09:55:19Z Indexed on 2010/05/01 9:57 UTC
Read the original article Hit count: 216

Filed under:
|
|

My Html action link takes me to a view where i can see the details.. For Ex:http://localhost:1985/Materials/Details/4 But it shows error,

The model item passed into the dictionary is of type 
'System.Data.Linq.DataQuery`1[CrMVC.Models.ConstructionRepository+Materials]' 
but this dictionary requires a model item of type 
'CrMVC.Models.ConstructionRepository+Materials'.

And my model is...

         public IQueryable<Materials> GetMaterial(int id)
        {
            return from m in db.Materials
                            join Mt in db.MeasurementTypes on m.MeasurementTypeId equals Mt.Id
                            where m.Mat_id == id
                            select new Materials()
                            {
                                Id = Convert.ToInt64(m.Mat_id),
                                Mat_Name = m.Mat_Name,
                                Mes_Name = Mt.Name,
                            };
        }
        public class Materials
        {
            private Int64 id;
            public string mat_Name;
            public string mes_Name;
            public Int64 Id
            {
                get
                {
                    return id;
                }
                set
                {
                    id = value;
                }
            }
            public string Mat_Name
            {
                get
                {
                    return mat_Name;
                }
                set
                {
                    mat_Name = value;
                }
            }
            public string Mes_Name
            {
                get
                {
                    return mes_Name;
                }
                set
                {
                    mes_Name = value;
                }
            }
        }
    }

and my controller method...

public ActionResult Details(int id)
{
    var material = consRepository.GetMaterial(id).AsQueryable();
    return View("Details", material);
}

Any suggestion what am i missing here?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about model