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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:00:43+00:00 2026-05-26T08:00:43+00:00

So First i tried to create ViewData[whatever] object like so ViewData[Blah] = new selectList(Do

  • 0

So First i tried to create ViewData[“whatever”] object like so

ViewData["Blah"] = new selectList("Do cool stuff");

That resulted in an error saying and int32 is not an IEnummerable (no shit);

Then i tried another approach

List<SelectItem> coolList  = db.Select(new selectItem("bunch of cool stuff"));

ViewData["Blah"] = coolLost;

That resulted in a selectedIndex that would never change.

Now for my final attempt.

I’ve added ICollections to my model.
Added the collectionId.

For example

public class Horse
{
    public int Id { get; set; }
    [Required(ErrorMessage = "Name is required")]
    public string Name { get; set; }
    [Required(ErrorMessage = "Gender is required")]
    public int? GenderId { get; set; }
    public string Color { get; set; }
    public int? LegTypeId { get; set; }
    public int? CharacterId { get; set; }
    public int Hearts { get; set; }
    public bool Retired { get; set; }
    // Parents
    public int? SireId { get; set; }
    public int? DamId { get; set; }
    // Internals
    public int Stamina { get; set; }
    public int Speed { get; set; }
    public int Sharp { get; set; }
    // Special
    public int Dirt { get; set; }
    // Externals
    public int Start { get; set; }
    public int Corner { get; set; }
    public int OutOfTheBox { get; set; }
    public int Competing { get; set; }
    public int Tenacious { get; set; }
    public int Spurt { get; set; }
    //Genders
    public virtual ICollection<Gender> Genders { get; set; }
    //LegTypes
    public virtual ICollection<LegType> LegTypes { get; set; }
    //Characters
    public virtual ICollection<Character> Characters { get; set; }
    //Dams
    public virtual ICollection<Horse> Dams { get; set; }
    //Sires
    public virtual ICollection<Horse> Sires { get; set; }
    //Races
    public virtual ICollection<Race> RaceResults { get; set; }
    //Training
    public virtual ICollection<Training> TrainingResults { get; set; }
}

and in my cshtml file.

   <div class="editor-label">
            @Html.LabelFor(horse => horse.GenderId)
        </div>
        <div class="editor-field">

            @Html.DropDownListFor(horse => horse.GenderId, new SelectList(Model.Genders, "Id", "Name", Model.GenderId), "-- Fill Out --")
            @Html.ValidationMessageFor(horse => horse.GenderId)   
        </div>

And that just gives me an error saying i have a null reference.

I am so out of ideas.

And then there is the even better one as you can see in my model.
i have a list of sires and a list of dams.

but they are both of type horse.
How do i manage to get all my horses in that list.

Thanks in advance for any advice that will trigger light bulbs in my head.

Also trying this right now:

var genders = horseTracker.Genders.Select(g => new SelectListItem { Text = g.Name, Value = g.Id.ToString() }).ToList();
            var legtypes = horseTracker.LegTypes.Select(l => new SelectListItem { Text = l.Name, Value = l.Id.ToString() }).ToList();
            var characters = horseTracker.Characters.Select(c => new SelectListItem { Text = c.Name, Value = c.Id.ToString() }).ToList();
            var sires = horseTracker.Horses.Where(h => h.Gender.Equals("Male") && h.Retired.Equals(true)).Select(h => new SelectListItem { Text = h.Name, Value = h.Id.ToString() }).ToList();
            var dams = horseTracker.Horses.Where(h => h.Gender.Equals("Female") && h.Retired.Equals(true)).Select(h => new SelectListItem { Text = h.Name, Value = h.Id.ToString() }).ToList();

        ViewData["Genders"] = genders;
        ViewData["LegTypes"] = legtypes;
        ViewData["Characters"] = characters;
        ViewData["Sires"] = sires;
        ViewData["Dams"] = dams;

This gives me an error saying that LinQ can’t use toString() apparently since that’s an unsafe method.

  • 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-26T08:00:44+00:00Added an answer on May 26, 2026 at 8:00 am

    actually,

    I fixxed it and the solution was WAY simpler than i expected.

        ViewData["Genders"] = new SelectList(horseTracker.Genders, "Id", "Name");
        ViewData["LegTypes"] = new SelectList(horseTracker.LegTypes, "Id", "Name");
        ViewData["Characters"] = new SelectList(horseTracker.Characters, "Id", "Name");
        ViewData["Sires"] = new SelectList(horseTracker.Horses.Where(h => h.Gender.Name.Equals("Male") && h.Retired.Equals(true)), "Id", "Name");
        ViewData["Dams"] = new SelectList(horseTracker.Horses.Where(h => h.Gender.Name.Equals("Female") && h.Retired.Equals(true)), "Id", "Name");
    

    And this in the cshtml

    @Html.DropDownListFor(horse => horse.GenderId, (SelectList)ViewData["Genders"])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently tried to create an object like this: var carousel = { $slider:
I am new to Wcf and tried to create my first Wcf services. Added
This is the first Python script I've tried to create. I'm reading a xml
I first time tried to subClassed an NSDate to give it 2 methods that
I tried to create one more new ASP.NET MVC application (with Entity Framework) and
Ive tried to create a stylesheet, its looks like this .MyStyle { /* IE6/7/8
I tried to create a simple ComboBox: var combo1 = new Ext.form.ComboBox({ store: [1,2,3],
I just tried to create my first function in octave, it looks as follows:
I am trying to do some error handling in java bytecode. I first tried
I just tried to create my first plpgsql function. When executing the script, I

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.