Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC - No Viewdata item with key of type 'IEnumerable<SelectListItem>'
    primarykey
    data
    text
    <p>I'm new to MVC and ASP.NET and am looking to learn a bit, so I'm trying to make some trivial applications to learn the ins and outs.</p> <p>Well, I'm trying to make a dropdown box show a list of books where it would show the title of the book but post the book_id [primary key]</p> <p>The error I get is:: There is no ViewData item with the key 'book_id' of type 'IEnumerable'.</p> <p>Here is what is in my view:</p> <pre><code> &lt;p&gt; &lt;label for="book_id"&gt;Book:&lt;/label&gt; &lt;%= Html.DropDownList("book_id" , (IEnumerable&lt;SelectListItem&gt;)ViewData["Books"]) %&gt; &lt;%= Html.ValidationMessage("book_id", "*") %&gt; &lt;/p&gt; </code></pre> <p>Here is what's in my controller</p> <pre><code> // GET: /Home/Create //This is the form creation. [Authorize] public ActionResult Create() { this.ViewData["Books"] = new SelectList(_entities.BookSet.ToList(), "book_id", "Title"); return View(); } // // POST: /Home/Create //This sends it to the DB [AcceptVerbs(HttpVerbs.Post) , Authorize] public ActionResult Create([Bind(Exclude="problem_id")] Problem inProblem) { try { // TODO: Add insert logic here Models.User user = getUser(User.Identity.Name); if (user != null) { inProblem.user_id = user.user_id; } _entities.AddToProblemSet(inProblem); _entities.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } } </code></pre> <p>And my Books table looks like this</p> <pre><code> book_id title publisher language isbn </code></pre> <p>I'm assuming this is a trivial newbie mistake; but I'm not having much luck figuring it out. Any help would be great</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.
    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