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

  • Home
  • SEARCH
  • 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 7907697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:35:11+00:00 2026-06-03T11:35:11+00:00

My knowledge is .Net is lacking tremendously. Any assistance on the following would be

  • 0

My knowledge is .Net is lacking tremendously. Any assistance on the following would be appreciated:

I have a Customer Model:

public class CustomerModel
{

private DBEntities db = new DBEntities();

public List<CustomerModel> CustomerResultModel { get; set; }

[Required]
[DisplayName("Customer Number")]
public long ID { get; set; }

[StringLength(50)]
public string Firstname { get; set; }

[StringLength(50)]
public string Organisation { get; set; }

[StringLength(500)]
[DisplayName("Address Line 1")]
public string AddressLine1 { get; set; }

[StringLength(50)]
[Required(ErrorMessage = "A Postcode is required")]
public string Postcode { get; set; }

public CustomerModel GetCustomerResults(string q)
{
    CustomerModel model = new CustomerModel();

    var res = from s in db.CMUCustomers select s;

    foreach (var result in res)
    {
        CustomerModel modelres = new CustomerModel();

        modelres.ID = result.ID;
        modelres.CustomerName = result.Firstname;
        modelres.AddressLine1 = result.AddressLine1;
        modelres.Postcode = result.Postcode;
        modelres.Organisation = result.Organisation;

        model.CustomerResultModel.Add(modelres);
    }

    return model;
  }

}

In my Controller I have:

private CustomerModel customerResults = new CustomerModel();

public ViewResult Search(string q)
{

CustomerModel model = customerResults.GetCustomerResults(q);
return View(model);

}

I however get an error on ‘model.CustomerResultModel.Add(modelres);’ stating ‘Object reference not set to an instance of an object.’. Any suggestions to what I could be doing wrong?

Thanks

  • 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-03T11:35:14+00:00Added an answer on June 3, 2026 at 11:35 am

    The error it’s telling you that you don’t have instanced the List, you need to instance the attribute with the List when you define the constructor of your class or before to assign the values

    if you want to be in the constructor

    public CustomerModel ()
    {
        this.CustomerResultModel  = new List<CustomerModel>()
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fair bit of knowledge of Java and C#.NET (prefer C#). What
I have no knowledge of Python. I started with .NET and than learned PHP.
My knowledge on common table expressions is lacking at the moment so any help
I do not have much knowledge about the interoperability between .net and visual foxpro.
I don't have too much knowledge of compilers and how .Net optimizes the generated
Has anyone had experience of or got any knowledge about the VFP to .Net
i dont have much knowledge about asp.net, i have to do one simple search
We have developers with knowledge of these languages - Ruby , Python, .Net or
Forgive my somewhat-lacking ASP.NET knowledge for this question :) Here's the scenario: I'm playing
Given the following controller class: public class ProjectController : Controller { public ActionResult List()

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.