I have the following code to generate selectlistitems to show in my dropdownlist.
public static IEnumerable<SelectListItem> ToSelectListItems(this IEnumerable<BlogCategory> categories, int selectedId)
{
return categories.OrderBy(category => category.Category)
.Select(category => new SelectListItem
{
Selected = (category.ID == selectedId),
Text = category.Category,
Value = category.ID.ToString()
});
}
I want to use this helper class to generate other list items then BlogCategory. How can I accomplish this?
You can make a base class for your lookup entities: