In case I have a multiselect in html,and I want to separate the selected values within the combobox and separate by commas when I list all users with their replies 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;
}
user.Typesmodelaggregate = string. Join(",", user.typesModel);
– Gustavo Santos