I have Months' DropDownListFor
and I want to select current month as default I tried this two options
@{
var currentMonth = month.FirstOrDefault(x => x.Id == DateTime.Now.Month).Id;
}
1.
@Html.DropDownListFor(x => x.monthId, new SelectList(month, "Id", "Name", currentMonth ))
2.
@Html.DropDownListFor(x => x.monthId, month.Select(x => new SelectListItem
{ Text = x.Name.ToString(), Value = x.Id.ToString(), Selected = (x.Id == currentMonth ?true:false)})),
but neither works. How can I achieve my goal?