Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8164269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:16:52+00:00 2026-06-06T19:16:52+00:00

I have a class called Property that I only need to display a few

  • 0

I have a class called Property that I only need to display a few items from in my List view. I created a Linq query to return only those items in my controller Index method. I have instantiated

List<Property> props = new List<Property>();

within the Index method of the controller but when I try to “Add” to the props list “props.Add(getProp);” I’m receiving this error:

“The best overloaded method match for System.Collections.Generic.List<PropertyEntities.Property>.Add(PropertyEntities.Property)
has some invalid arguments”

I’ve included the PropertyControler Index Method, and the Property class that I’m working with below:

     public ViewResult Index()
    {
        //var properties = db.Properties.Include(p => p.PropertyType);

        var getProp = from p in db.Properties
                      orderby p.PropName
                      select new
                      {
                          p.PropertyID,
                          p.PropName,
                          p.PropertyStatus,
                          p.City,
                          p.State,
                          p.Bedrooms,
                          p.PropertyType
                      };

        List<Property> props = new List<Property>();
        props.Add(getProp);
        return View(props);
    }

public partial class Property 
{
    //public int temp { get; set; }

    // Values stored in the view Garage DropDownList
    public enum GarageType{ None = 0, One = 1, Two = 2, Three = 3, Four = 4, Carport = 5, Other = 6 }

    public enum PropertyStatusType { Leased = 0, Available = 1, Selling = 2, Sold = 4 }

    [Required]
    [ScaffoldColumn(false)]
    public int PropertyID { get; set; }

    [Required(ErrorMessage="Generic name for referencing."),
     StringLength(30, ErrorMessage = "Property name max length is 30 characters."),
     Display(Name="Property Name", Prompt="Enter Property Name")]
    public string PropName { get; set; }

    [Required(ErrorMessage="Select a status for this property."),
    Display(Name="Property Status")]
    public int PropertyStatus { get; set; }

    // used in corolation with the property PropertyStatus
    // to allow dropdown list to except Enum values
    // PropertyStatusType
    public PropertyStatusType PropertyEnumStatus
    {
        get { return (PropertyStatusType)PropertyStatus; }
        set { PropertyStatus = (int)value; }
    }

    [Required(ErrorMessage="Select a property type.")]
    public int PropertyTypeId { get; set; }

    [Required(ErrorMessage="Address is required."),
     StringLength(75, ErrorMessage="Address max length is 75 characters.")]
    public string Address { get; set; }

    [Required(ErrorMessage = "City name is required."),
     StringLength(25, ErrorMessage = "City max length is 25 characters.")]
    public string City { get; set; }

    [Required(ErrorMessage = "State abbreviation is required."),
     StringLength(2, ErrorMessage = "State max length is 2 characters.")]
    public string State { get; set; }

    [Required(ErrorMessage = "Zip Code is required."),
     StringLength(5, ErrorMessage = "Zip Code max length is 5 numbers."),
    Range(00001, 99999)]
    [Display(Name="Zip Code")]
    public string ZipCode { get; set; }

    [Required(ErrorMessage="Square feet is required."),
     Display(Name="Square Feet")]
    public int SquareFeet { get; set; }


    [Required(ErrorMessage = "Number of bedrooms is required."),
    Range(0,10)]
    public int Bedrooms { get; set; }

    [Required(ErrorMessage="Number of bathrooms is required."),
    Range(0,20)]
    public int Bathrooms { get; set; }

    public int Garage { get; set; }


    // used in corolation with the property Garage
    // to allow dropdown list to except Enum values
    // of GarageType
    [NotMapped]
    public GarageType GarageEnumValue
    {
        get { return (GarageType)Garage; }
        set{ Garage = (int)value; }
    }

    [Display(Name="Morgage Amount"),
    Range(0.00, 100000000.00)]
    public Nullable<decimal> MonthlyMortgage { get; set; }

    [Display(Name="HOA Dues"), 
    Range(0.00, 1000.00)]
    public Nullable<decimal> HousingDues { get; set; }

    [Display(Name="Property Tax"),
    Range(0.0, 100000000.00)]
    public Nullable<decimal> Tax { get; set; }

    [Display(Name="Property Insurance"),
    Range(0.0, 100000000.00)]
    public Nullable<decimal> Insurance { get; set; }

    [Display(Name="Assessed Value"),
    Range(0.0, 100000000.00)]
    public Nullable<decimal> AssessedValue { get; set; }

    [Display(Name="Current Value"),
    Range(0.0, 100000000.00)]
    public Nullable<decimal> CurrentValue { get; set; }

    [DataType(DataType.MultilineText)]
    [StringLength(500, ErrorMessage="You have reached the allotted 500 characters.")]
    public string Notes { get; set; }

    public virtual ICollection<Lease> Leases { get; set; }

    public virtual PropertyType PropertyType { get; set; }

    public virtual ICollection<Service> Services { get; set; }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:16:53+00:00Added an answer on June 6, 2026 at 7:16 pm

    create a ViewModel class when you need a subset of an entity’s property, or a mix of subsets of entities properties

    public class PropertyViewModel {
        public int PropertyID {get;set;}
        public string PropName {get;set;}
        public int PropertyStatus {get;set;}
        //etc.
        public PropertyType PropertyType {get;set;}
    }
    

    then select new PropertyViewModel for each property (or use AutoMapper, which would be fine for your need https://github.com/AutoMapper/AutoMapper )

    public ViewResult Index()
        {
            var properties = db.Properties.Include(prop => prop.PropertyType)
                     .Select(p => new PropertyViewModel {
                                     PropertyID = p.PropertyID,
                                     PropName = p.PropName,
                                     //etc.
                                  })
                      .ToList();
            return View(properties);//View's model should be of tye IList<PropertyViewModel> (or IEnumerable)
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called Question that has a property called Type. Based on
I have a Menu class that has a IQueryable property called WebPages. In the
I have a class, called DateField , that has a string Value property. If
I have an entity called File, I created a partial class with a property
I created an HtmlHelper method called DisplayListBoxFor that will need display a textual representation
I have a class TxRx with a property called Common. Common then has a
I have a class with a int property called X. I binded it to
I have a class with a Property called 'Value' which is of type Object.
I have a Data Class called MyTable, and the source property is TABLE (table
I have a base class with a property called Name, which has an XmlText

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.