KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I found many questions and answers related to this issue but nothing worked for me I am creating a dropdown list like this @Html.DropDownListFor(m => m.SchoolYears, new SelectList(Model.SchoolYears, "YearId", "StartDates", Model.CurrentYearId), new { @class = "field_Dropdown", style = "width:100px;",onchange="return searchStudents();" }) ( Model.CurrentYearId is of type int ) But it never lets current year selected. From this post, I got that we should use string for selected value (although I don't know why because it allows object for selected value) DropDownList SelectList SelectedValue issue so I tried all these variations new SelectList(Model.SchoolYears, "YearId", "StartDates", Model.CurrentYearId.ToString()) new SelectList(Model.SchoolYears, "YearId", "StartDates", 2) new SelectList(Model.SchoolYears, "YearId", "StartDates", "2") But they even didn't work. There is way to create the select list through linq query or foreach loop and mark selected property of each item but why the above doesn't work?
Tags (comma-separated)
Save Edits
Cancel