Bind DropDownListFor from Database in ASP.Net Core MVC

on Oct 11, 2021 05:16 AM

Hello Experts

I am seeking your guidance to help with what I believe is simple but still have no knowledge of how it is done I have a very simple web application with only 3 pages in core.

The main page is a registration page that has a dropdown to select Job Category, I have the following code.

<div class="form-group">
     <label asp-for="JobCategory" class="control-label">Job Category</label>
     @Html.DropDownListFor(m => m.JobCategory, new SelectList(Enum.GetNames(typeof(JobCategory))), "Select Job Category", new { @class = "form-control" })

Can you please guide me to either, how I modify what I have currently get the list but I need to use the DESCRIPTION instead?

Or how to populate the dropdown list items from JobCayegories SQL table, the application is already connected to the SQL DB via ConnectionStrings


Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Oct 11, 2021 05:24 AM