In case I have a multiselect in html, and I want to separate the selected values inside the combobox and separate by commas the time I list all users with their responsive types of requests.
public IEnumerable<UserDataModel> Get()
{
UserDataModel userModel = new UserDataModel();
//var reg = ctx.User.Include(x => x.Area.Name).Include(x =>x.RequestType);
var users = ctx.User.OrderBy(u => u.Name).Select(u => new
UserDataModel
{
typesModel = u.RequestType.Select(x => new RequestTypeModel
{
Id = x.IdRequestType,
Name = x.Name
}).ToList()
}).ToList();
foreach (var user in users)
{
var strTypesModel = "";
foreach (var typesModel in user.typesModel)
{
strTypesModel = strTypesModel + typesModel.Name;
user.TypesModelAggregate = string.Join(",", user.typesModel);
}
}
return users;
}