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 6236143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:47:53+00:00 2026-05-24T10:47:53+00:00

I have the following viewmodel, public class SiteAdminCreateViewModel { public Customer Customer { get;

  • 0

I have the following viewmodel,

public class SiteAdminCreateViewModel
{
    public Customer Customer { get; private set; }
    public CustomerSite CustomerSite { get; private set; }
    public SelectList CustomerNames { get; private set; }

    public SiteAdminCreateViewModel(CustomerSite customerSite, Customer customer)
    {
        CustomerSite = customerSite;
        Customer = customer;
        CustomerNames = new SelectList(customer.CustomerName);
    }
}

And the following methods in my repository for returning a list of customers and a list of CustomerSites

 public IQueryable<CustomerSite> GetCustomerSites
    {
        get { return context.CustomerSites; }
    }
    public IQueryable<Customer> GetCustomers
    {
        get { return context.Customers; }
    }

When i instanitiate the viewmodel in my controller im wanting to return the list of customers to passs to the select list in the viewmodel.

 public ViewResult Create() 
    {
        CustomerSite customerSite = new CustomerSite();
        var customer = repository.GetCustomers.ToList();
        return View(new SiteAdminCreateViewModel(customerSite, customer));       
    }

But the return line throws the error

cannot convert from System.Collections.Generic.List’ to ‘CustomerOrders.Domain.Entities.Customer

I think this is because i have the customer variable defined in the Viewmodel of type Customer but im trying to pass a list of customers?

Can anyone offer any advice on where i am going wrong here?

Do i need to define both the Customer type and the CustomerNames select list type in the viewmodel, i defined the Customer Object only so i can use it to pass the Customers to the select list but im not sure if this is the best way to do this?

Any advice anyone can offer for a newbie, will be much appreciated.

  • 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-05-24T10:47:53+00:00Added an answer on May 24, 2026 at 10:47 am

    Your SiteAdminCreateViewModel class’ constructor is defined as follows:

    public SiteAdminCreateViewModel(CustomerSite customerSite, Customer customer) {
       ...
    }
    

    Its second argument is of type Customer.

    You’re passing var customer = repository.GetCustomers.ToList() to it, whose type is List<Customer>.


    When i instanitiate the viewmodel in my controller im wanting to
    return the list of customers to passs to the select list in the
    viewmodel.

    If I understand what you’re saying correctly, you’re just trying to pass the customers list to build a SelectList.

    First of all, you seem to be passing a string to the SelectList constructor. This would not even compile (read System.Web.Mvc.SelectList).

    What you’d need to do is change SiteAdminCreateViewModel‘s constructor like

    public SiteAdminCreateViewModel(CustomerSite customerSite, IEnumerable<Customer> customers) {
       /* ... */
       CustomerNames = new SelectList(customers, "CustomerId", "CustomerName");
    }
    

    CustomerId and CustomerName being properties of the Customer class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following ViewModel public class NewCustomerViewModel { public long CustomerId {get;set;} public
I have a ViewModel as such: public class EmployeeViewModel { Employees employee{ get; set;
I have following ViewModel: public class Bulletin1ViewModel { [Required] public String NumberDelegations { get;
I have the following ViewModel public class ShowQuestionsViewModel { public String CategoryName { get;
I have the following ViewModel: public class AllQuestionsInCategoriesViewModel { public string Category_Name { get;
Why doesn't my viewModel get inherited? I have the following viewModels: public class BaseViewModel
I have following ViewModel: public IEnumerable<SelectListItem> SelectAdminsInGroup { get; set; } public IEnumerable<SelectListItem> SelectAdminsNotInGroup
I have the following model: public class Product { public int Id { get;
I have the following viewmodel: public class ViewModel { [Display(Name = firstname, ResourceType =
I have following ViewModel containing NumberOfAdults fields. public class SearchView { public int NumberOfAdults

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.