I have a view with two drop-downs, weekend Day 1 and weekend Day 2. I am in edit mode and from action I am passing my select list like this:
var WeekList1 = new SelectList(new List<SelectListItem>
{
new SelectListItem { Value = "", Text = "Select Day" },
new SelectListItem { Value = "1", Text = "Sunday" },
new SelectListItem { Value = "2", Text = "Monday" },
new SelectListItem { Value = "3", Text = "Tuesday" },
new SelectListItem { Value = "4", Text = "Wednesday" },
new SelectListItem { Value = "5", Text = "Thursday" },
new SelectListItem { Value = "6", Text = "Friday" },
new SelectListItem { Value = "7", Text = "Saturday" }
}, "Value", "Text", model.weekendDay1);
var WeekList2 = new SelectList(new List<SelectListItem>
{
new SelectListItem { Value = "", Text = "Select Day" },
new SelectListItem { Value = "1", Text = "Sunday" },
new SelectListItem { Value = "2", Text = "Monday" },
new SelectListItem { Value = "3", Text = "Tuesday" },
new SelectListItem { Value = "4", Text = "Wednesday" },
new SelectListItem { Value = "5", Text = "Thursday" },
new SelectListItem { Value = "6", Text = "Friday" },
new SelectListItem { Value = "7", Text = "Saturday" }
}, "Value", "Text", model.weekendDay2);
ViewBag.WeekEnd1 = WeekList1;
ViewBag.WeekEnd2 = WeekList2;
I am creating same list twice just to pass different selected values. Is there any way to create it only once and pass it with different selected values. I do not want to crate new database table for this one.
Update:
@Html.DropDownList("WeekEnd1", null, htmlAttributes: new { @class = "form-control" })