how to get data from dropdownlist RRS feed

  • Question

  • User569149469 posted

    how to get data in to dropdownlist using .net core and wat is the use UIHint in mvc

    Monday, November 26, 2018 11:24 PM


  • User61956409 posted

    Hi phmaspnet,

    how to get data in to dropdownlist using .net core

    You can refer to the following example to populate DropDownList and get the selected data.

    TestDDL View:

    <div class="row">
        <div class="col-md-4">
            <form asp-action="UserSelection">
                <div class="form-group">
                    <select asp-for="ItemIndex" asp-items="@Model.ItemList"></select>
                <div class="form-group">
                    <input type="submit" value="Submit" class="btn btn-default" />

    TestDDL action:

    public IActionResult TestDDL()
        List<item> items = new List<item>() { new item() { Id = "1", Value = "Item1" }, new item() { Id = "2", Value = "Item2" }, new item() { Id = "3", Value = "Item3" } };
        TestViewModel model = new TestViewModel();
        model.ItemList = new SelectList(items.AsEnumerable(), "Id", "Value");
        return View(model);

    TestViewModel class:

    public class TestViewModel
        public string ItemIndex { get; set; }
        public SelectList ItemList { get; set; }

    item class:

    public class item
        public string Id { get; set; }
        public string Value { get; set; }

    UserSelection action:

    public string UserSelection(string ItemIndex)
        return $"The index of your selected option is {ItemIndex}";

    Test Result:

    wat is the use UIHint in mvc

    UIHintAttribute specifies the template or user control that Dynamic Data uses to display a data field, for detailed information, please check the link.

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 28, 2018 7:37 AM