You can try the following:
IEnumerable<SelectListItem> customerList = new List<SelectListItem>();
The error you received is reasonable because
The var keyword tells the compiler to infer the type of the variable from the expression on the right side of the initialization statement.
Alternatively, you can try the following:
var customerList = customerlist.Select(m => new SelectListItem() { Text = m.NAME, Value = m.NAME.ToString(), });
The reason the second assignment will work is because the compiler can infer the type of the variable in this way, since it knows what type of LINQ query is returned.
source share