Hire Me

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

Easy fix to the bug when scaffolding views and controllers in Visual Studio 2015

Posted on Saturday, January 7, 2017 at 3:08 PM into csharp code gotcha by Steve Woods

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.

;

Comments

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