Hii,
I have the following code.Can anyone help me with the view code to populate IEnumerable<SelectListItem>GroupsList data into the dropdownlist..where GroupsList is a list of records in a table with id and name as columns.I also need a default ''select value" in dropdown list .
My controller code: public ActionResult GetMyGroups()
{
var groupslist = _adminSystemServices.GetGroups();
var model = new GroupsViewModel
{
GroupsList = groupslist.Select(x => new SelectListItem
{
Text = x.Name,
Value = x.Id.ToString()
})
};
return View(model);
}
Model: public class GroupsViewModel : HeaderViewModel
{
public Guid Id { get; set; }
public String Name { get; set; }
public Guid GroupId { get; set; }
public Guid ClaimId { get; set; }
public String Description { get; set; }
public List<ClaimViewModel> AvailableClaimsList { get; set; }
public IEnumerable<SelectListItem> GroupsList { get; set; }
public List<ClaimViewModel> GroupClaimsList { get; set; }
public ClaimViewModel ClaimViewModel { get; set; }
}