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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:28:14+00:00 2026-05-26T13:28:14+00:00

I have a model with 3 properties, as I mentioned in a previous question

  • 0

I have a model with 3 properties, as I mentioned in a previous question (this is a different question of course), the model called “Something” and it has 3 properties:

int SomethingID
string Name
List<System.Drawing.Color>

(of course it’s not the original code, want to save some readers by saving some length)

And my Initializer is this:

protected override void Seed(DatabaseContext context)
{
    var somethings = new List<Something>
    {
        new Something
        {
            Name="blah blah", Colors= { Color.Black, Color.Red }
        }
    };
        somethings.ForEach(s => context.Somethings.Add(s));
        context.SaveChanges();

        base.Seed(context);
}

When I try to get those colors inside a view the colors are empty.
If I set a breakpoint inside the Initializer right after I constructed somethings, I get a property called Colors with a Count of 2 (so it’s fine, I have the object with my ID, name, and colors).

But when it’s inside the view, the debugger shows the Colors‘s count is 0, and as you can guess – the list is empty.

inside the View

    Colors:
    @foreach (var itemColor in item.Colors)
    {
        itemColor.ToString();
    }

Desired result:
Colors: Black Red

Current result:
Colors: (empty)

  • 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-26T13:28:14+00:00Added an answer on May 26, 2026 at 1:28 pm

    You are just listing the colors in code block but not writing them to the screen. try

    Colors:
        @foreach (var itemColor in item.Colors)
        {
            @(itemColor.ToString())
        }
    

    My favorite place to get quick reference for razor syntax
    http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx

    EDIT

    Change your object to include this string property that will translate named colors to and from the database to your Colors List Property. This way your object is in full control of translating the information to the properties and you can continue using them as normal.

            public string SavedColors
            {
                get { return Colors.Aggregate("", (current, color) => current + (color.Name + ",")).TrimEnd(','); }
                set
                {
                    Colors = value.Split(',').Select(Color.FromName).ToList();
                }
            }
            [NotMapped]
            public List<System.Drawing.Color> Colors { get; set; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model Question with a field called userid , before one ask
I have model Foo which has field bar. The bar field should be unique,
I have model Article it has field title with some text that may contain
I have a model, Thing, that has a has_many with ThingPhoto, using Paperclip to
We have a model with properties decorated with [Required] which works great for validation.
I have an edit view that is displaying some model properties as plain text
I have a situation where I have Model A that has a variety of
I have a model with complex properties like: public partial class CrmDefinedEntity { private
Let's assume that we have a Model with several properties on it and we
I have a table in my database called Task. Task has the following fields:

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.