SelectListItems not appearing in the Edit view when Scaffolding Controllers and Views with MVC Core in Visual Studio 2015

Posted on Saturday, January 7, 2017 at 3:08 PM into csharp, code & gotcha by Steve Woods.
Roughly a 1 minute read.

When scaffolding Controllers and Views (for say, a simple CMS Admin functionality for a given Object), you may find that your Select dropdowns are not populated with any SelectListItems (in the form of <option> tags).

This is because there is a bug in the Visual Studio 2015 scaffolder which, while correctly implemented in the Create view, is not in the Edit view.

You will end up with:

<select asp-for="PropertyId" asp-items="ViewBag.MyItems" />

But what you need is:

<select asp-for="PropertyId" asp-items="ViewBag.MyItems"></select>

Easy to miss.



Please consider what you post!
Chillax if you're angry.

RSS 2.0 Feed | Copyright © 1999 - 2018 Steve Woods, All Rights Reserved - Warning, may contain nuts.