Hi,@ladd4luv_22
I tried as below and it could work:
in pagemodel:
public class TestModel : PageModel
{
public SelectList DropDownList { get; set; }
public void OnGet()
{
var List_Mode = GetDropDownList();
DropDownList = new SelectList(List_Mode, "PredefineID", "Predefine");
}
//assuming you get the list successfully from db,I tried with hard coding
public List<ListMode> GetDropDownList()
{
var List_Mode = new List<ListMode>()
{
new ListMode(){PredefineID=1,Predefine="Class"},
new ListMode(){PredefineID=2,Predefine="Subject"},
new ListMode(){PredefineID=3,Predefine="Option"},
new ListMode(){PredefineID=4,Predefine="Status"}
};
return List_Mode;
}
}
in page:
@page
@model RazorPage7._22.Pages.TestModel
<form method="post">
<select id="ddlFruits" name="PredefineID" asp-items="@Model.DropDownList">
<option value="0">Please select</option>
</select>
</form>
Result:
----------
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards
RuikaiFeng