Question

Im trying add roles to a drop dropdown box but im getting the error thats below. please help.

Model Code

  public SelectListItem RolesForUser {get; set;}

Controller Code

 var roles = Roles.GetRolesForUser(model.username);
 model.RolesForUser=roles.select(m => new SelectListItem() 
 {Value=m.ToString(),Text=m.ToString()});

Error 21 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'System.Web.Mvc.SelectListItem'. An explicit conversion exists (are you missing a cast?)

Was it helpful?

Solution

declare RolesForUser as List<SelectListItem> RolesForUser and change LINQ query as

model.RolesForUser=roles.select(m => new SelectListItem() {Value=m.ToString(),Text=m.ToString()}).ToList();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top