Created
December 18, 2017 07:50
-
-
Save A-Programmer/2a7211cfc5667726fbc344e700046ca0 to your computer and use it in GitHub Desktop.
How to set drop down list items in ASP.NET Core from database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In action method of HomeController.cs : | |
[HttpGet] | |
public ActionResult TestAction() | |
{ | |
ViewBag.Categories = db.Categories.ToList(); | |
return View(); | |
} | |
in View (TestAction.cshtml): | |
<select asp-for="Menu.Id" asp-items="@(new SelectList(@ViewBag.Categories,"Id","Title"))"> | |
<option disabled selected>Choose Category</option> | |
</select> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment