My code
C#
public enum StatusEnum
{
NotRegistered = 0,
Pending = 1,
Accepted = 2,
}Code
Select Status :My code
public enum StatusEnum
{
NotRegistered = 0,
Pending = 1,
Accepted = 2,
} Select Status :Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted Sep 14, 2023, 1:40 AM EDT
You can use ViewBag to bind the data directly within your EJS view.
For example:
public enum StatusEnum { NotRegistered = 0, Pending = 1, Accepted = 2, } public class HomeController : Controller { public IActionResult Index() { var statusList = Enum.GetValues(typeof(StatusEnum)) .Cast() .Select(e => new { Text = e.ToString(), Value = (int)e }) .ToList(); ViewBag.StatusList = statusList; return View(); } }In your view you can access ViewBag.StatusList and bind it to your ejs-dropdownlist:
If you prefer not to use ViewBag and want to bind the data directly within your EJS view, you can use JavaScript to bind the enum values to the dropdownlist.
For example:
Select Status : // Define a JavaScript array with the enum values var statusData = [ { Text: "Not Registered", Value: 0 }, { Text: "Pending", Value: 1 }, { Text: "Accepted", Value: 2 } ]; // Get a reference to the dropdownlist var drpStatus = document.getElementById('drpStatus').ej2_instances[0]; drpStatus.dataSource = statusData; drpStatus.refresh();Mohammad HussainRank #513 · 4.8K reputationPosted Sep 14, 2023, 2:56 AM EDT
function initializeDropDown() { var statusEnum = @Html.Raw(Json.Serialize(Enum.GetValues(typeof(StatusEnum)).map(value => ({ Text: value, Value: value })))); var dropDownList = new ej.dropdowns.DropDownList({ dataSource: statusEnum, fields: { text: 'Text', value: 'Value' }, placeholder: 'Select Status', popupHeight: '220px', allowFiltering: true }); dropDownList.appendTo('#drpStatus'); } // Call the function to initialize the DropDownList when the page loads document.addEventListener("DOMContentLoaded", function () { initializeDropDown(); });