Convert SelectList to List<T>

Sanhita Roy 1 Reputation point
2023-10-13T16:00:56.8233333+00:00

Can you please show how do I convert SelectList items to generic list

ViewModel

public SelectList Countries { get; set; }

Model

public List<EmissionCountry> Countries { get; set; } = new List<EmissionCountry>();

I want to convert all the select list items into the list

 public static Emission MapUserDetailViewModel(UserDetailViewModel viewModel)         
{             
return new Emission             
{                 
Countries = viewModel.Countries,                 
MarketSegments = viewModel.MarketSegments,                 
InquiryTypes = viewModel.InquiryTypes             
};         
}

I am getting error cannot implicitly convert type system.web.mvc.selectlist to system.collections.generic.list<EmeaWebsite.Model.EmissionCountry>


.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,647 questions
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,710 questions
{count} votes