Link to home
Start Free TrialLog in
Avatar of Robb Hill
Robb HillFlag for United States of America

asked on

Help with dropdownlist - LINQ

I am trying to create a select list ...that basically just creates a user entry for my user to select options to be inserted into the database.

I have this in my controller...which Is not complete  Here roles is a list of value and label.....What am I missing here..and how would you then use this to display on view....to I need something in my view model as well?

       private IEnumerable<SelectListItem> GetRoles()
        {
            IContactEntityEditService contactEntityEditService = DependencyResolver.Current.GetService<IContactEntityEditService>();
            List<string> roles = contactEntityEditService.GetContactLinkedEntitiesRoles();
           
            roles.Select(x => new SelectListItem
                                {
                                    Value = x.value,
                                    Text = x.label
                                });

            return new SelectList(roles, "Value", "Text");
        }

Open in new window

Avatar of Dorababu M
Dorababu M
Flag of India image

How about this
roles.Select(x => new SelectListItem
{
     Value = x.value,
     Text = x.label
}).ToList();

Open in new window

Avatar of Robb Hill

ASKER

x has no values ...from roles...


 private IEnumerable<SelectListItem> GetRoles()
        {
            IContactEntityEditService contactEntityEditService = DependencyResolver.Current.GetService<IContactEntityEditService>();
            List<string> roles = contactEntityEditService.GetContactLinkedEntitiesRoles();

            roles.Select(x => new SelectListItem
            {
                Value = x.value,
                Text = x.label
            }).ToList();

            return new SelectList(roles, "Value", "Text");
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Robb Hill
Robb Hill
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
my solution works adn shows how to implement with this approach