Note that there are some explanatory texts on larger screens.

plurals
  1. POEF 4.1 + MVC Dropdownlist issues
    primarykey
    data
    text
    <p>So First i tried to create ViewData["whatever"] object like so</p> <pre><code>ViewData["Blah"] = new selectList("Do cool stuff"); </code></pre> <p>That resulted in an error saying and int32 is not an IEnummerable (no shit);</p> <p>Then i tried another approach </p> <pre><code>List&lt;SelectItem&gt; coolList = db.Select(new selectItem("bunch of cool stuff")); ViewData["Blah"] = coolLost; </code></pre> <p>That resulted in a selectedIndex that would never change.</p> <p>Now for my final attempt.</p> <p>I've added ICollections to my model. Added the collectionId.</p> <p>For example</p> <pre><code>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&lt;Gender&gt; Genders { get; set; } //LegTypes public virtual ICollection&lt;LegType&gt; LegTypes { get; set; } //Characters public virtual ICollection&lt;Character&gt; Characters { get; set; } //Dams public virtual ICollection&lt;Horse&gt; Dams { get; set; } //Sires public virtual ICollection&lt;Horse&gt; Sires { get; set; } //Races public virtual ICollection&lt;Race&gt; RaceResults { get; set; } //Training public virtual ICollection&lt;Training&gt; TrainingResults { get; set; } } </code></pre> <p>and in my cshtml file.</p> <pre><code> &lt;div class="editor-label"&gt; @Html.LabelFor(horse =&gt; horse.GenderId) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.DropDownListFor(horse =&gt; horse.GenderId, new SelectList(Model.Genders, "Id", "Name", Model.GenderId), "-- Fill Out --") @Html.ValidationMessageFor(horse =&gt; horse.GenderId) &lt;/div&gt; </code></pre> <p>And that just gives me an error saying i have a null reference.</p> <p>I am so out of ideas.</p> <p>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.</p> <p>but they are both of type horse. How do i manage to get all my horses in that list.</p> <p>Thanks in advance for any advice that will trigger light bulbs in my head.</p> <p>Also trying this right now:</p> <pre><code>var genders = horseTracker.Genders.Select(g =&gt; new SelectListItem { Text = g.Name, Value = g.Id.ToString() }).ToList(); var legtypes = horseTracker.LegTypes.Select(l =&gt; new SelectListItem { Text = l.Name, Value = l.Id.ToString() }).ToList(); var characters = horseTracker.Characters.Select(c =&gt; new SelectListItem { Text = c.Name, Value = c.Id.ToString() }).ToList(); var sires = horseTracker.Horses.Where(h =&gt; h.Gender.Equals("Male") &amp;&amp; h.Retired.Equals(true)).Select(h =&gt; new SelectListItem { Text = h.Name, Value = h.Id.ToString() }).ToList(); var dams = horseTracker.Horses.Where(h =&gt; h.Gender.Equals("Female") &amp;&amp; h.Retired.Equals(true)).Select(h =&gt; 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; </code></pre> <p>This gives me an error saying that LinQ can't use toString() apparently since that's an unsafe method.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload