3
Hello Mark,
Above error indicates that you are trying to assign List to single value object property.
You just need to change your viewmodel and need to create two more properties, then you can assign list of property model to your viewmodel property.
public class MyWM
{
public MYWM()
{
Property = new Property ();
Student = new Student();
}
public List<Property> Properties { get; set; }
public Student Student { get; set; }
public string? name { get; set; }
public string? familyname { get; set; }
public decimal? productcode { get; set; }
public Assets AssestD { get; set; }
}
Accepted 3
The error message you’re seeing is because you’re trying to assign a List<Project.Data_Access.Model.Property>
to a single Project_web.ViewModels.Property
object. These types are not the same, even though they have the same properties.
In your ViewModel, you have a Property
object, but what you’re getting from the database is a list of Property
objects. You need to change your ViewModel to hold a list of Property
objects instead of a single one.
Here’s how you can modify your ViewModel:
public class MyWM
{
public List<Property> Properties { get; set; }
public Student Student { get; set; }
public MyWM()
{
Properties = new List<Property>();
Student = new Student();
}
}
And then in your controller, you can assign the list of properties from the database to your ViewModel:
MYWM model = new MYWM();
model.Properties = DbContext.Property.ToList();
This way, your ViewModel now holds a list of Property
objects, which matches what you’re getting from the database. This should resolve the error you’re seeing.
Thanks

1
dear Jignesh Kumar &
Naimish Makwana thanks for the reply I like to give my viewmodel entity values from database , one more question as my property class is having propertyTypeID which is another table property category i would like to get its text like property type id text as well and show in the list how to do that ?
1
i already wrote even i made it list still I am unable to assign it to my viewmodel object , a fair question I would like to ask if my Dbcontext class with entity property and my viewmodel is having entity List<property> still on my index view when i say myviewmodel.myobjectOfentity=Dbcontext.property.TOList() the issue persists.