aspnetcore: Why does SelectList no longer support a constructor which takes a list of disabled items?

In Asp.Net MVC the SelectList has a constructor overload of the form:

public SelectList(
    IEnumerable items,
    object selectedValue,
    IEnumerable disabledValues)

However, in Asp.Net Core MVC, there is no longer a constructor which takes disabled items as a parameter:

public SelectList(
        IEnumerable items,
        string dataValueField,
        string dataTextField,
        object selectedValue,
        string dataGroupField)

Was this a conscious decision or would you accept a pull request to support this use case?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (9 by maintainers)

Most upvoted comments

@RyanTaite the SelectListGroups are compared work reference equality, not by Name because multiple groups may have the same name. If you want less-granular grouping, create the SelectListGroups first e.g.

var groups = dbSet
    .AsNoTracking()
    .Select(materialType => materialType.Company.Name)
    .Distinct()
    .Select(name => new SelectListGroup { Name = name })
    .ToDictionary(group => group.Name, StringComparer.Ordinal);

return dbSet
    .AsNoTracking()
    .OrderBy(x => x.Company.Name)
    .ThenBy(x => x.Name)
    .Select(materialType => new SelectListItem
    {
        Value = materialType.Id.ToString(),
        Text = materialType.Name,
        Group = groups[materialType.Company.Name],
        Disabled = !materialType.IsActive,
    }
    .ToArray();

Being new here, what is the recommended way to “show interest” for this enhancement request? +1? Posting in this thread?